用户授权
1.给单个用户授权访问权限
GRANT 权限 ON 数据库名.表名 TO ‘用户名’@‘访问主机’ IDENTIFIED BY ‘密码’;
GRANT SELECT ON test.* TO 'test'@'localhost' IDENTIFIED BY 'test@123456';
GRANT ALL ON test.* TO 'test'@'localhost' IDENTIFIED BY 'test@123456';
flush privileges;
2.给多用户授权访问权限
GRANT 权限 ON 数据库名.表名 TO ‘用户名1’@‘访问主机1’, ‘用户名2’@‘访问主机2’ IDENTIFIED BY ‘密码’;
GRANT SELECT ON test.* TO 'test'@'localhost', 'test2'@'localhost' IDENTIFIED BY 'test@123456';
flush privileges;
3.给所有用户授权访问其权限
GRANT 权限 ON 数据库名.表名 TO ‘用户名’@‘%’;
GRANT SELECT ON test.* TO 'test'@'localhost';
flush privileges;
4.查看用户权限
SHOW GRANTS FOR ‘用户名’@‘访问主机’;
SHOW GRANTS FOR 'test'@'localhost';
flush privileges;
5.取消用户权限
REVOKE 权限 ON 数据库名.表名 FROM ‘用户名’@‘访问主机’;
REVOKE SELECT,INSERT ON test.* FROM 'test'@'localhost';
flush privileges;