How To Create a New User and Grant Permissions in MySQL
How To Create a New User and Grant Permissions in MySQL
MySQL is a popular open-source relational database management system that allows you to store, manage, and retrieve data efficiently. In this tutorial, you will learn how to create a new user and grant permissions in MySQL using SQL commands.
Step 1: Connect to MySQL
The first step is to connect to MySQL using a command-line interface such as MySQL Shell or the MySQL client. You will need to enter your MySQL username and password to log in.
mysql -u username -p
Step 2: Create a New User
To create a new user in MySQL, you can use the CREATE USER command followed by the username and password. Replace 'newuser' and 'password' with your desired username and password.
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
If you want to allow the user to connect from any host, you can use '%' instead of 'localhost'.
Step 3: Grant Permissions
To grant permissions to the new user, you can use the GRANT command followed by the privileges and database name. Replace 'newuser' and 'database_name' with your desired values.
GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'@'localhost';
If you want to grant specific privileges, you can replace 'ALL PRIVILEGES' with the desired privileges such as 'SELECT', 'INSERT', 'UPDATE', 'DELETE', etc.
Step 4: Flush Privileges
After granting permissions to the new user, you need to flush the privileges for the changes to take effect.
FLUSH PRIVILEGES;
Step 5: Verify Permissions
You can verify the permissions of the new user using the SHOW GRANTS command.
SHOW GRANTS FOR 'newuser'@'localhost';
This will display the privileges granted to the new user.
Conclusion
In this tutorial, you learned how to create a new user and grant permissions in MySQL using SQL commands. By following these steps, you can create new users and control their access to your MySQL databases.
Keywords: MySQL, user, permissions, SQL, tutorial, CREATE USER, GRANT, FLUSH PRIVILEGES, SHOW GRANTS.
Комментарии
Отправить комментарий