一、权限分类(常用)
select 查询权限
create 创建权限
insert 插入记录
update 修改值
drop删除表等
all可以代表除了grant之外的所有权限
二、创建用户
1.只创建用户
1 create user 'bai'@'localhost'; identified by '123';
2.创建用户时一起授权;
grant select on db1.* to 'bai'@'localhost' identified by '123'; # db1库中的所有表
三、授权范围
#针对所有库的授权:*.* grant select on *.* to 'egon1'@'localhost' identified by '123'; #只在user表中可以查到egon1用户的select权限被设置为Y #针对某一数据库:db1.* grant select on db1.* to 'egon2'@'%' identified by '123'; #只在db表中可以查到egon2用户的select权限被设置为Y #针对某一个表:db1.t1 grant select on db1.t1 to 'egon3'@'%' identified by '123'; #只在tables_priv表中可以查到egon3用户的select权限 #针对某一个字段: grant select (id,name),update (age) on db1.t3 to 'egon4'@'localhost' identified by '123'; #可以在tables_priv和columns_priv中看到相应的权限
四、收回权限
# 收回用户alex在db1数据库中的select权限 revoke select on db1.* from 'alex'@'%';