Mysql对权限的控制,大致分为2个阶段:
一、用户有没有连接权限:
mysql如何判断用户有没有权限连接,依据3个参数:host、user和password。用户这3个信息,存储在mysql库的user表中;
1.修改host字段,使用ip可以连接:
update user set host = '192.168.61.132' where user = 'root';
flush privileges;
2.删除用户名为空的记录:
delete from user where user = '';
flush privileges;
3.修改用户密码:
update user set password = password('xxxxxx') where user = 'xxx';
flush privileges;
二、用户有没有权限执行此操作:
mysql库的db表中存储着用户对整个库的操作权限,tables_priv表中存储着用户对表的操作权限;
1.查看所有用户:select Host,User,Password from user;
2.新增一个用户:
grant [权限1,权限2,权限3...] on *.* to user@'host' identified by 'password';
常用权限有:all,create,drop,insert,delete,update,select
实例:
grant all on *.* to lisi@'192.168.61.%'identifiedby '123456';
flush privileges;
3.收回权限:
revoke all on *.* from lisi@'192.168.61.%';
flush privileges;