In this post, we will learn to create user in MySQL server and also assign a role to specific database.
Make sure you have already logged in to your MySQL server with root credentials.
CREATE USER 'newUser'@'serverAddress' IDENTIFIED BY 'newPassword';
Let’s create a user called `myUser` with the password `myPass123`
CREATE USER 'myUser'@'localhost' IDENTIFIED BY 'myPass123';
Now, the user is created in the database.
To give the specific permission to the user, we can follow the following syntax:
GRANT type_of_permission ON database_name.table_name TO ‘username’@'localhost’;
Let’s take a following scenario.
We have a database
myDb and the user
myUser should manage the database
myDb then we can use following command:
GRANT ALL ON myDb.* TO ‘myUser’@'localhost’;