· Tutorial ·

How to create a new user and grant permissions in MySQL

Here is a detailed manual on how to create a new user and grant permissions in MySQL:

Step 1: Login to MySQL

To create a new user and grant permissions in MySQL, you must log in to your MySQL server. You can do this in a number of ways, but a common way is to open a terminal or command line and type the following:

mysql -u root -p

This will log into MySQL with the user root. It will ask you to enter your root password before continuing.

Step 2: Create a new user

Once you are logged into MySQL, you can create a new user using the following command:

´CREATE ´USER 'nombre_de_usuario'@'localhost' IDENTIFIED BY 'contraseña';

In this command, you must replace username with the username you want to create and password with the password you want to assign to that user.

Step 3: Grant permissions to the new user

Once you have created the user, you must grant them permissions so that they can interact with the databases. You can do this using the following command:

GRANT permiso ON nombre_de_base_de_datos.* TO 'nombre_de_usuario'@'localhost';

In this command, permission represents the type of permission you want to grant, such as SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX, etc. nombre_de_base_de_datos is the name of the database you want to grant permissions on, and nombre_de_usuario is the user name you want to grant permissions to.

You can grant multiple permissions by separating them by commas. For example, if you want to grant SELECT and INSERT permissions on the my_database to the user my_user, you can use the following command:

GRANT SELECT, INSERT ON my_database.* TO 'my_user'@'localhost';

Step 4: Update permissions

Once you have granted permissions to the new user, you must update the permissions in MySQL for them to take effect. You can do this using the following command:

FLUSH PRIVILEGES;

This command will update the permissions in MySQL so that the newly created user can interact with the databases.

Step 5: Exit MySQL

Once you have created a new user and granted permissions, you can exit MySQL using the following command:

exit

This will log out of MySQL and return to the terminal or command line.

success Done! You have now created a new user and given it permissions to interact with the databases in MySQL.

i