What is the method for granting permissions to mysql users?
In MySQL, you can grant user privileges using the following syntax:
- Grant full permissions to the user.
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
- Granting specific permissions to the user.
GRANT SELECT, INSERT, UPDATE ON database_name.* TO 'username'@'localhost';
- Grant full access to the user and allow access to all databases.
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
- Granting users remote access permission:
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'%' IDENTIFIED BY 'password';
In the above syntax, ‘database_name’ represents the name of the database, ‘username’ represents the user’s name, ‘localhost’ means the user can only access from the local host, ‘%’ means the user can access from anywhere, ‘password’ represents the user’s password. Once authorization is complete, use the command FLUSH PRIVILEGES; to apply the authorization.