MySQL: Create database, user and assign user

 

Let’s supose you want to create an user called “myuser” with the password “mypassword” and the database called “mydb”.

Create Database:

$mysql> CREATE DATABASE mydb;
Query OK, 1 row affected (0.00 sec)

Create User:

$mysql> CREATE USER ‘myuser‘@’localhost’ IDENTIFIED BY ‘mypassword‘;
Query OK, 0 rows affected (0.02 sec)

Assign user to database:

$mysql> GRANT ALL PRIVILEGES ON mydb.* TO ‘myuser‘@’localhost’;
Query OK, 0 rows affected (0.01 sec)