1.查询用户
use mysql;
select host,user from user;
–因为表里的字段很多,只查重要的host和user
2.创建用户
create user ‘用户名’@‘主机名’ inentified by ‘密码’;
create user 'zcm'@'localhost' identified by 'abc';
3.修改用户密码
alter user ‘用户名’@‘主机名’ identified with mysql_native_password by ‘新密码’;
alter user 'zcm'@'localhost' identified with mysql_native_password by 'zcm';
4.删除用户
drop user ‘用户名’@‘主机名’;
drop user ‘zcm’@'localhost';
主机名可以使用%通配符,使用通配符表示此用户可以任意一个地方登录,不限于本地登录;
5.查询权限
show grants for ‘用户名’@‘主机名’
use mysql;
select user,host from mysql.user;
create user 'zcm'@'*' identified by 'zcm';
show grants for 'root'@'localhost';
2.授予权限
grant 权限1,权限2 on 数据库名.表名 to ‘用户名’@‘主机名’;
show grants for 'zcm'@'*';
grant all on bank.* to 'zcm'@'*';
3.撤销权限
revoke 权限1,权限2 on 数据库名.表名 from ‘用户名’@‘主机名’;
revoke all on bank.* from 'zcm'@'*';
show grants for 'zcm'@'*';
注意,多个权限可以使用逗号进行分隔开,如果一次性全部权限,可以使用all 或是all privileges
授权时,数据库名和表名均可以使用*代替所有权限。
可以使用
grant all privileges on *.* to 'zcm'@'*'; --授予所有权限
revoke all privileges on *.* from 'zcm'@‘*’; --撤销所有权限
详细的权限列表就不赘述了