What is the method for granting permissions to mysql users?

In MySQL, you can grant user privileges using the following syntax:

  1. Grant full permissions to the user.
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
  1. Granting specific permissions to the user.
GRANT SELECT, INSERT, UPDATE ON database_name.* TO 'username'@'localhost';
  1. Grant full access to the user and allow access to all databases.
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
  1. 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.

Leave a Reply 0

Your email address will not be published. Required fields are marked *