1. Cấp quyền
Để cấp quyền cho user đối với database ta sử dụng lệnh GRANT với cú pháp sau:
GRANT [privilege] ON [database_name].[table_name] TO '[user_name]'@'localhost';
2. Thu hồi quyền đã cấp
Thu hồi quyền đã cấp cho user ta sử dụng lệnh REVOKE với cú pháp:
REVOKE [privilege] ON [database_name].[table_name] TO '[user_name]'@'localhost';
3. Ý nghĩa các tham số
– database_name: là tên cơ sở dữ liệu. Nếu tất cả các database thì dùng dấu *.
– table_name: là tên bảng. Nếu tất cả các bảng thì table_name là dấu *.
– user_name: là user được cấp quyền.
– privilege: là quyền cấp cho user_name. Các giá trị và ý nghĩa của privilege xem bảng bên dưới:
| Privilege | Meaning |
| ALL [PRIVILEGES] | Sets all simple privileges except GRANT OPTION |
| ALTER | Enables use of ALTER TABLE |
| CREATE | Enables use of CREATE TABLE |
| CREATE TEMPORARY TABLES | Enables use of CREATE TEMPORARY TABLE |
| DELETE | Enables use of DELETE |
| DROP | Enables use of DROP TABLE |
| EXECUTE | Not implemented |
| FILE | Enables use of SELECT … INTO OUTFILE and LOAD DATA INFILE |
| INDEX | Enables use of CREATE INDEX and DROP INDEX |
| INSERT | Enables use of INSERT |
| LOCK TABLES | Enables use of LOCK TABLES on tables for which you have the SELECT privilege |
| PROCESS | Enables the user to see all processes with SHOW PROCESSLIST |
| REFERENCES | Not implemented |
| RELOAD | Enables use of FLUSH |
| REPLICATION CLIENT | Enables the user to ask where slave or master servers are |
| REPLICATION SLAVE | Needed for replication slaves (to read binary log events from the master) |
| SELECT | Enables use of SELECT |
| SHOW DATABASES | SHOW DATABASES shows all databases |
| SHUTDOWN | Enables use of MySQLadmin shutdown |
| SUPER | Enables use of CHANGE MASTER, KILL, PURGE MASTER LOGS, and SET GLOBAL statements, the MySQLadmin debug command; allows you to connect (once) even if max_connections is reached |
| UPDATE | Enables use of UPDATE |
| USAGE | Synonym for privileges |
| GRANT OPTION | Enables privileges to be granted |
nosomovo