Python-4.44 数据库权限管理

授权表

  • user 该表放行的权限,针对:所有数据,所有库下所有表,以及表下的所有字段
  • db 该表放行的权限,针对:某一数据库,该数据库下的所有表,以及表下的所有字段
  • tables_priv 该表放行的权限。针对:某一张表,以及该表下的所有字段
  • columns_priv 该表放行的权限,针对:某一个字段

1、创建账号

# 本地账号
create user 'winnie1'@'localhost' identified by '123';  # mysql -uwinnie1 -p123

# 远程帐号
create user 'winnie2'@'192.168.31.10' identified by '123'; # mysql -uwinnie2 -p123 -h 服务端ip
create user 'winnie3'@'192.168.31.%' identified by '123'; # mysql -uwinnie3 -p123 -h 服务端ip
create user 'winnie3'@'%' identified by '123'; # mysql -uwinnie3 -p123 -h 服务端ip

2、授权

user:*.*
db:db1.*
tables_priv:db1.t1
columns_priv:id,name

grant all on *.* to 'winnie1'@'localhost';
grant select on *.* to 'winnie1'@'localhost';
revoke select on *.* from 'winnie1'@'localhost';

grant select on db1.* to 'winnie1'@'localhost';
revoke select on db1.* from 'winnie1'@'localhost';


grant select on db1.t2 to 'winnie1'@'localhost';
revoke select on db1.t2 from 'winnie1'@'localhost';

grant select(id,name),update(age) on db1.t2 to 'winnie1'@'localhost';
上一篇:MYSQL 连接设置


下一篇:mysql给予权限给普通用户