How to create a new user and grant permissions in MySQL?
MySQL is a popular open-source relational database management system used for web applications. Creating a new user and granting permissions in MySQL is a crucial step in securing your database. In this article, we will guide you on how to create a new user and grant permissions in MySQL.
Step 1: Login to MySQL
The first step is to log in to MySQL as a root user. To do this, open your command prompt and type the following command:
mysql -u root -p
You will be prompted to enter the root password. Once you have entered the correct password, you will be logged in to MySQL.
Step 2: Create a new user
The next step is to create a new user. To create a new user, type the following command in the MySQL command prompt:
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password';
In the above command, replace ‘new_user’ with the username of your choice and ‘password’ with a strong password.
Step 3: Grant permissions
The next step is to grant permissions to the new user. To grant permissions, type the following command:
GRANT ALL PRIVILEGES ON * . * TO 'new_user'@'localhost';
In the above command, replace ‘new_user’ with the username of your choice.
Step 4: Verify permissions
To verify the permissions granted to the new user, type the following command:
SHOW GRANTS FOR 'new_user'@'localhost';
This command will display the permissions granted to the new user.
Step 5: Flush privileges
The last step is to flush the privileges to ensure that the changes take effect immediately. To flush the privileges, type the following command:
FLUSH PRIVILEGES;
Conclusion
Creating a new user and granting permissions in MySQL is a crucial step in securing your database. By following the above steps, you can create a new user and grant the necessary permissions. Remember to choose a strong password for your new user to ensure the security of your database.