DEV Community

Emmanuel Gautier
Emmanuel Gautier

Posted on • Originally published at emmanuelgautier.com on

MySQL Users & Permissions

Database administration includes users and permissions management. Most of the time, a UI like, MySQL Workbench or PHPMyAdmin, is available to perform users management actions. Here, we will see how to do some MySQL users and permissions management with SQL queries.

User creation

First action, user creation with a password. Two ways to perform this action depending on the way you want to pass the password.

-- Not hashed password in the query (not very secure)
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';

-- With hashed password
SELECT PASSWORD('password'); -- Création du Hash du mot de passe
CREATE USER 'user'@'localhost' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB9900DFG1E6Y89F4';
Enter fullscreen mode Exit fullscreen mode

User renaming

Now, let's see how to rename an already created user with the following query.

RENAME USER 'user'@'localhost' TO 'user2'@'localhost';
Enter fullscreen mode Exit fullscreen mode

Top comments (0)