HowTo : Create MySQL Database from the Command Line

Creating MySQL Database from the command line is quite a common task.

We'll create database named test_db with a user named john and a password pass.

User will have all privileges on this database and will be allowed to connect only from the localhost.

Step 1 : Log into MySQL shell as root.

$ mysql -u root -p

Step 2 : Create a database test_db.

mysql> CREATE DATABASE test_db;

Step 3 : Add a user named john for the new database. Assign him a password pass and give him a permission to access only from the localhost.

mysql> GRANT ALL PRIVILEGES ON test_db.* TO john@localhost IDENTIFIED BY 'pass';


Now you can log into MySQL server as john.

$ mysql -u john -p

Execute the following command to list databases :