steps to create mysql database

17 07 2009

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.

Create database

mysql> CREATE DATABASE databasename;

Create user

mysql> CREATE USER username

Grant permissions for the user

mysql> GRANT ALL PRIVILEGES ON databasename.* to username@localhost IDENTIFIED BY 'password';

Flush privileges


Quit mysql prompt

mysql> \q

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