创建新用户
mysql> use mysql;
Database changed
对新用户增删改
创建用户:
create user 'andy' @'192.168.1.1' identified by 'password';
create user 'andy' @ '%' identified by 'password';
删除用户:
drop user 'andy' @ 'ip_address';
修改用户:
rename user 'andy' @ 'ip_address' to 'jack' @ 'ip_address';
修改密码
set password for 'andy' @'ip_address' = paswword('new_password');
对当前用户授权管理
查看权限
show grants for 'root'@'localhost';
授权
andy用户仅对db1.t1文件有查询、插入和更新的操作
grant select ,insert,update on db1.t1 to "andy"@'%';
# 表示有所有的权限,除了grant这个命令,这个命令是root才有的。andy用户对db1下的t1文件有任意操作
grant all privileges on db1.t1 to "andy"@'%';
#andy用户对db1数据库中的文件执行任何操作
grant all privileges on db1.* to "andy"@'%';
#andy用户对所有数据库中文件有任何操作
grant all privileges on *.* to "andy"@'%';
#取消权限
# 取消andy用户对db1的t1文件的任意操作
revoke all on db1.t1 from 'andy'@"%";
# 取消来自远程服务器的andy用户对数据库db1的所有表的所有权限
revoke all on db1.* from 'andy'@"%";
取消来自远程服务器的andy用户所有数据库的所有的表的权限
revoke all privileges on *.* from 'andy'@'%';