创建用户
create user 'clown'@'%' identified by mysql_native_password '123456';
授权
grant all privileges on nacos.* to 'clown'@'%' with grant option;
grant select,create,delete,update on nacos.* to 'clown'@'%' with grant option;
收回权限
revoke select,create,delete,grant option on nacos.* from 'clown'@'%';
revoke all privileges,grant option from 'clown'@'%';
-- 或者
revoke all privileges on nacos.* from 'clown'@'%';
revoke grant option on nacos.* from 'clown'@'%';
授予什么权限就回收什么权限
grant select on *.* to 'clown'@'%' with grant option;
授予全局权限,权限信息保存在mysql.user表中
select * from mysql.user where user='clown'\G;
*************************** 1. row ***************************
Host: %
User: clown
Password: *06C0BF5B64ECE2F648B5F048A71903906BA08E5C
Select_priv: Y
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
Reload_priv: N
Shutdown_priv: N
Process_priv: N
File_priv: N
Grant_priv: Y
References_priv: N
Index_priv: N
Alter_priv: N
Show_db_priv: N
Super_priv: N
Create_tmp_table_priv: N
Lock_tables_priv: N
Execute_priv: N
Repl_slave_priv: N
Repl_client_priv: N
Create_view_priv: N
Show_view_priv: N
Create_routine_priv: N
Alter_routine_priv: N
Create_user_priv: N
Event_priv: N
Trigger_priv: N
Create_tablespace_priv: N
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin: mysql_native_password
authentication_string:
password_expired: N
grant select on nacos.* to 'clown'@'%' with grant option;
授予数据库权限,权限信息保存在mysql.db表中
select * from mysql.db\G;
*************************** 1. row ***************************
Host: %
Db: nacos
User: clown
Select_priv: Y
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
Grant_priv: Y
References_priv: N
Index_priv: N
Alter_priv: N
Create_tmp_table_priv: N
Lock_tables_priv: N
Create_view_priv: N
Show_view_priv: N
Create_routine_priv: N
Alter_routine_priv: N
Execute_priv: N
Event_priv: N
Trigger_priv: N
grant select on nacos.user to 'clown'@'%' with grant option;
授予某张表权限,权限信息保存在mysql.tables_priv表中
select * from mysql.tables_priv;
+-----------+-----+-------+------------+----------------+---------------------+--------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+-----------+-----+-------+------------+----------------+---------------------+--------------+-------------+
| % |nacos| clown | user | root@localhost | 0000-00-00 00:00:00 | Select,Grant | |
+-----------+-----+-------+------------+----------------+---------------------+--------------+-------------+
grant select(name) on nacos.user to 'clown'@'%' with grant option;
授予某个字段的权限,权限信息保存在mysql.columns_priv表中
select * from mysql.columns_priv;
+-----------+-----+-------+------------+-------------+---------------------+-------------+
| Host | Db | User | Table_name | Column_name | Timestamp | Column_priv |
+-----------+-----+-------+------------+-------------+---------------------+-------------+
| % |nacos| clown | user | name | 0000-00-00 00:00:00 | Select |
+-----------+-----+-------+------------+-------------+---------------------+-------------+
当使用
revoke all privileges on *.* from 'clown'@'%';
回收的只是全局的权限,clown用户其他的权限,比如对nacos数据库的权限,对user表的权限,对某个字段的权限仍然持有。 所以为了回收用户的所有权限,使用
revoke all privileges,grant option from 'clown'@'%';
这是条固定语法,all privileges和grant option必须都有