user [> ssl_option:
SSL | X509 | CIPHER 'cipher' | ISSUER 'issuer' | SUBJECT 'subject'
with_option:
GRANT OPTION | MAX_QUERIES_PER_HOUR count | MAX_UPDATES_PER_HOUR count | MAX_CONNECTIONS_PER_HOUR count | MAX_USER_CONNECTIONS count
示例:
MariaDB [mysql]> grant all privileges on hellodb.* to 'test'@'%';
MariaDB [mysql]> grant select,update on hellodb.students to 'test'@'%';
MariaDB [mysql]> grant select(Name,Age,ClassID) on hellodb.students to 'test'@'%';
也可以对某些基本表创建视图之后,再对视图进行用户权限授权:
MariaDB [hellodb]> create view stu_base as select Name,Age,ClassID from students;
MariaDB [hellodb]> grant all on hellodb.stu_base to 'test'@'%';
取消授权/收回授权:
REVOKE语句:
REVOKE priv_type [(column_list)] [, priv_type [(column_list)]] ...
ON [object_type] priv_level
FROM user [, user] ...
REVOKE ALL PRIVILEGES, GRANT OPTION
FROM user [, user] ...
示例:
MariaDB [mysql]> revoke delete on hellodb.* from 'test'@'%';
MariaDB [mysql]> revoke all on hellodb.students from 'test'@'%';
MariaDB [mysql]> revoke select(Age,ClassID) on hellodb.students from 'test'@'%';
注意:在取消已经做出的授权时,REVOKE语句所指定的priv_level部分应该和授权时GRANT语句所指定的priv_level保持绝对一致;否则判定此次取消授权的操作失败;
示例:前提是testdb数据库中包含有tb1和tb2两张表;
MariaDB [testdb]> grant all on testdb.* to 'test'@'%';
MariaDB [testdb]> revoke all on testdb.tb2 from 'test'@'%';
ERROR 1147 (42000): There is no such grant defined for user 'test' on host '%' on table 'tb2'
正确的取回授权的方式:
MariaDB [testdb]> revoke all on testdb.* from 'test'@'%';
MariaDB [testdb]> grant all on testdb.tb1 to 'test'@'%';
此时,'test'@'%'用户就只有对testdb数据库中tb2表有所有操作权限;
查看用户的授权:
SHOW GRANTS语句:
SHOW GRANTS [FOR user]