How to create a new database, user, and grant permissions using mysql (command line)


In this simple tutorial we will discuss how to make a database using the mysql command line tool.

Assuming you are not viewing the mysql command line client, you will need to access this:

mysql -u yourname -p

... Once you enter your password you should see the mysql command line client.


To create a new database, user and grant permissions, simply:


1. Create a new user

CREATE USER 'your_new_user_here'@'localhost' IDENTIFIED BY 'your_password_here';

2. Create a new database

CREATE DATABASE 'new_database_name';

3. Assign permissions to your new user, and new database

GRANT ALL PRIVILEGES ON 'new_database_name' . * TO 'your_new_user_here'@'localhost';

4. Flush privileges - do not forget this!

FLUSH PRIVILEGES;