Create a user in MySQL and grant database permissions.
To create a user and grant permissions to a database in MySQL, you need to follow these steps:
- Login to the MySQL server with root permissions. You can use the following command to login:
mysql -u root -p
- Create a new user. You can create a new user by using the following command and replacing it with the username and password you want to create:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
- Grant users permission. You can grant users specific permissions using the following command, replacing it with the permissions and database name you want to grant.
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
Please note that in the command above, ‘database_name’ should be replaced with the name of the database you want to authorize. If you want to grant a user permission to all databases, you can replace database_name.* with *.*.
4. Refresh permissions. After making changes to permissions, you need to refresh MySQL’s permission table for the changes to take effect. You can use the following command to refresh permissions:
FLUSH PRIVILEGES;
After completing the above steps, your user will be created and granted the corresponding permissions.