Creating a database in mysql is easy with just CREATE TABLE command. For any application just creating database is not enough. We have to create one user and we need to give privileges for that user on the database. These are the commands that will create database, user and give permissions for the user to the database.
Go to mysql prompt
shell>mysql -u root -p
Use -p option if password is set for the root.
mysql> CREATE DATABASE databasename;
mysql> CREATE USER username
Grant permissions for the user
mysql> GRANT ALL PRIVILEGES ON databasename.* to username@localhost IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;
Quit mysql prompt
Note: Untill we flush the privileges we can’t get the new privileges that we assigned.
That’s it we created database, user and gave permissions to user to the database. Now use the following command to go to database with the username
shell> mysql -u username -p databasename