How to set user permissions and authorization in MySQL?

In MySQL, you can use the GRANT statement to set user permissions and privileges. Below are some common examples:

  1. Grant users access to the database.
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
  1. Authorized users are only allowed to query the database.
GRANT SELECT ON database_name.* TO 'username'@'localhost';
  1. The authorized user is only permitted to insert, update, and delete from the database.
GRANT INSERT, UPDATE, DELETE ON database_name.* TO 'username'@'localhost';
  1. revoke user privileges
REVOKE ALL PRIVILEGES ON database_name.* FROM 'username'@'localhost';

Please note that in the examples above, ‘username’ and ‘database_name’ represent the user and database names, respectively. In actual use, you need to replace them with the actual usernames and database names. Additionally, you can set more granular permissions using GRANT statements, such as granting users permission to operate on specific tables.

广告
Closing in 10 seconds
bannerAds