# 删除用户
drop user if exists 'user_name'@'localhost';
# 创建数据库用户
create user 'user_name'@'localhost' identified by 'mima.123456';
创建的用户名 连接方式('localhost'本地,'10.7.174.90:1'局域网,'10.7.174.%'此前缀的任意局域网,'%'任意连接方式) 密码要强密码,包括英文数字特殊符号
# 修改密码
alter user 'user_name'@'localhost'identified by 'mima.654321';
# 授予权限。
#连接方式不同,即便名字相同也不算是一样的
# hrs库的所有select查询权限,点后面可以放表名、视图名,更精确
grant select on hrs.* to 'user_name'@'localhost';
# insert权限
grant insert on hrs.* to 'user_name'@'localhost';
# 多个权限
grant select,insert,delete,update on hrs.* to 'user_name'@'localhost';
# hrs库的所有权限
grant all privileges on hrs.* to 'user_name'@'localhost';
# 所有库的所有权限,但跟root管理员还是有区别,没有权限授予权限
grant all privileges on *.* to 'user_name'@'localhost';
# 想当于root管理员
grant all privileges on *.* to 'user_name'@'localhost' with grant option;
# 收回权限
# 授权与收权要对应,hrs.* -> hrs.* , *.* -> *.*
revoke insert on hrs.* from 'user_name'@'localhost';
revoke all privileges on *.* from 'user_name'@'localhost';