创建用户
create user '用户名'@'IP地址' identified by '密码';
删除用户
drop user '用户名'@'IP地址';
修改用户
rename user '用户名'@'IP地址' to '新用户名'@'IP地址' ;
修改密码
第一种方法:
set password for '用户名'@'IP地址'=Password('新密码')
第二种方法:
alter user '用户名'@'IP地址' identified by '新密码';
第三种方法(忘记密码时,必须使用此方法修改密码):
UPDATE mysql.user SET authentication_string=password('QFedu123!') WHERE user='root' and host='localhost';
grant 权限 on 数据库.表 to '用户'@'IP地址' identified by '密码'; -- 授权并设置密码
revoke 权限 on 数据库.表 from '用户'@'IP地址' -- 取消权限
show grants for '用户'@'IP地址';
针对所有库和表的权限,比如 . 。 去 mysql.user 中查看
select * from mysql.user where user='shark'\G
针对具体到库的权限,比如db_name.* 。 去 mysql.db 中查看
select * from mysql.db where user='shark'\G
针对具体表的授权,在 mysql.tables_priv 中查看
select * from mysql.tables_priv where user='shark'\G



grant



MySQL [servers]> grant all on server10.0.122.%' identified by 'QFedu123@';



关于数据库和表
对于目标数据库以及内部其他:
数据库名.* 数据库中的所有
数据库名.表 指定数据库中的某张表
数据库名.存储过程 指定数据库中的存储过程
. 所有数据库
关于用户和 IP
用户名@IP地址 用户只能在此 IP 下才能访问
用户名@192.168.1.% 用户只能在此 IP 段下才能访问(通配符%表示任意)
用户名@%.shark.com
用户名@% 用户可以再任意IP下访问(默认IP地址为%)
create user 'shark'@'%';
grant all privileges on . to 'shark'@'%' identified by '123';
flush privileges;
刷新权限,使用设置生效
grant select,show view,trigger on . to 'backup'@'%' identified by 'QFedu123!';
grant select on . /设置查询数据的权限在所有的库和表/
to 'shark_2'@"%" /指定用户名和来源 ip/
identified by '123'; /设置密码/
网友评论