一、创建账号
# 本地账号 create user 'egon1'@'localhost' identified by '123'; # mysql -uegon1 -p123; #远程账号 create user 'egon1' @'192.168.31.10' identified by '123'; # mysql -uegon1 -p123 -h 服务端ip # 某个网段的可以登录 create user 'egon1' @'192.168.31.%' identified by '123'; # mysql -uegon1 -p123 -h 服务端ip # 所有的客户端都可以登录 create user 'egon1'@'%' identified by '123'; # mysql -uegon1 -p123 -h 服务端ip
权限表
user:*.* 所有库下的所有表都有权限
db:db1.* 对库下所有的表都有权限
tables_priv:db1.t1 对库下的某一个表有权限
columns_priv:id,name 只能查id和name字段
放权
grant all on *.* to 'egon1'@'localhost'; # 开放所有权限 grant select on *.* to 'egon1'@'localhost'; # 开放全部的查看权限 grant select on db1.* from to 'egon1'@'localhost'; # 只对db1开放查看权限 select * from mysql.dbG grant select on db7.student to 'egon1'@'localhost'; # 精确到表级别 select * from mysql.tables_privG grant select(sid,sname), update(gender) on db7.student to 'egon1'@'localhost'; # 精确到字段,update是更新权限,只有gender可以被更改,但是还是不能被查看。 select * from mysql.columns_priv; # 查看是否授权成功
revoke select on *.* from 'egon1'@'localhost'; revoke select on db1.* from 'egon1'@'localhost'; revoke select on db7.student from 'egon1'@'localhost';