How to Create a New User and Assign Permissions in MySQL

18 ott 2023 1 min di lettura
How to Create a New User and Assign Permissions in MySQL
Indice dei contenuti


Creating a new user and assigning the appropriate permissions is an essential practice for managing your MySQL database securely and efficiently. This tutorial will walk you through the steps necessary to create a new user in MySQL and assign specific permissions to this user.

Step 1: Log in to MySQL

To get started, log in to your MySQL system using the following command:

mysql -u root -p

You will be prompted to enter the root user password.

Step 2: Creating a New User

To create a new user, run the following command, replacing 'newusername' and 'password' with your desired username and password:

CREATE USER 'newusername'@'localhost' IDENTIFIED BY 'password';

To verify user creation, run:

SELECT user FROM mysql.user;

You should see the new username in the returned list​.

Step 3: Assigning Permissions

MySQL offers a variety of permissions that can be assigned to users. Here is an example command to grant all permissions to a user on a specific database table:

GRANT ALL PRIVILEGES ON database.table TO 'newusername'@'localhost';

If you only want to grant specific permissions, such as INSERT, use the following command:

GRANT INSERT ON database.table TO 'newusername'@'localhost';

You can replace "INSERT" with other permission types like SELECT, UPDATE, DELETE, etc.

Step 4: Reload Privileges

After assigning permissions, it is important to reload privileges to ensure the changes take effect:



In this tutorial, we explored how to create a new user in MySQL and how to assign specific permissions to that user. By following these steps, you will be able to effectively manage access to your database while ensuring security and efficiency.

Buy me a coffeeBuy me a coffee

Supportaci se ti piacciono i nostri contenuti. Grazie.

Successivamente, completa il checkout per l'accesso completo a
Bentornato! Accesso eseguito correttamente.
Ti sei abbonato con successo a
Successo! Il tuo account è completamente attivato, ora hai accesso a tutti i contenuti.
Operazione riuscita. Le tue informazioni di fatturazione sono state aggiornate.
La tua fatturazione non è stata aggiornata.