用户授权
登录mysql数据库,授权,创建用户,设置密码
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
用户权限列表参考MySQL官网:https://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html
all privileges:表示将所有权限授予给用户。也可指定具体的权限,如:SELECT、CREATE、DROP等。
on:表示这些权限对哪些数据库和表生效,格式:数据库名.表名,这里写“*”表示所有数据库,所有表。如果我要指定将权限应用到test库的user表中,可以这么写:test.user
to:将权限授予哪个用户。格式:”用户名”@”登录IP或域名”。%表示没有限制,在任何主机都可以登录。比如:”aa”@”192.168.1.%”,表示aa这个用户只能在192.168.1.IP段登录
identified by:指定用户的登录密码
with grant option:表示允许用户将自己的权限授权给其它用户
刷新权限
flush privileges;
查看用户权限
grant select on *.* to 'aa'@'localhost' identified by '123456' with grant option;
show grants for 'aa'@'localhost';
回收权限
revoke select on *.* from 'aa'@'localhost';
flush privileges;
查看用户
select user from user;
此刻执行这句sql会报错,那么我们需要选中数据库
use mysql;
删除用户
drop user 'aa'@'localhost';