21 Feb

How to create MySQL database and user from command line

This is actually the base of MySQL command usage. By the help of a control panel we can simply create a database, create DB users, edit variables, set previeages etc. But in some situations it is necessary to manage these MySQL options via command line. Here I am explaining the commands for creating database and database user form command line.

Enter the mysql prompt by following the step below:

# mysql -u root -p

It then prompts for password. Enter the MySQL root password.


root@serversupportz[/]# mysql -u root -p
Enter password:

MySQL command to create a DB(Database).

mysql> CREATE DATABASE name_of_the_database;


mysql> CREATE DATABASE serversupportz_wp;
Query OK, 1 row affected (0.04 sec)

You can verify it by:


MySQL command to create a DB user.

mysql> CREATE USER name_of_the_database_user;


mysql> CREATE USER serversupportz_wp;
Query OK, 0 rows affected (0.07 sec)

You can find out the details of all users from mysql.user file:

mysql> select user from mysql.user;
mysql> select host, user, password from mysql.user;
mysql> select * from mysql.user;

Access the database

mysql> use name_of_the_database;


mysql> use serversupportz_wp
Database changed

That’s it 🙂

Share this

Leave a reply