Add users and databases in MySQL

Here is a quick 4 step command way to add user and database in MySQL.

1. You first need to create username and password:

CREATE USER 'database_user'@'localhost' IDENTIFIED BY 'database_password';

2. Then you need to create the database:

CREATE DATABASE database_name;

or

CREATE DATABASE database_name CHARACTER SET utf8 COLLATE utf8_general_ci;

Character set and collation are optional, if you don’t specify them, it will use server’s default.


3. You need to grant the user privileges to use the database:

GRANT ALL PRIVILEGES ON database_name.* TO 'database_user'@'localhost';

4. Now that everything is set, you need to reload the privilleges:

FLUSH PRIVILEGES;

Hope this helps 🙂


Photo by unsplash-logojesse orrico

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *