I - Login to MySQL
First we’ll login to the MySQL server from the command line with the following command:
Mã:mysql -u root -p
In this case, I’ve specified the user root with the -u flag, and then used the -p flag so MySQL prompts for a password. Enter your current password to complete the login.
You should now be at a MySQL prompt that looks very similar to this:
Mã:mysql>
II - Create MySQL User
We’ll create a user with the name testuser , and the password test123test
Mã:CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'test123test';
That’s it, congratulations! In just one command you’ve created your first MySQL user. However, this user won’t be able to do anything with MySQL until they are granted additional privileges. In fact, they won’t even be able to login without additional permissions.
III - Grant Permissions to MySQL User
The basic syntax for granting permissions is as follows:
Mã:GRANT permission ON database.table TO 'user'@'localhost';
Here is a short list of commonly used permissions :
GRANT ALL ON *.* TO 'testuser'@'localhost';
SELECT User,Host FROM mysql.user;
DROP USER 'testuser'@'localhost';