Mysql 新建用户并且授权用户的访问数据库权限以及可以对数据的操作类型

Mysql 5.6

-- 创建用户
CREATE USER 'joker'@'%' IDENTIFIED BY 'qweasd11';

-- 授权用户访问的数据库以及权限
grant all privileges on test.* to 'joker'@'%';
-- test为访问数据库
-- all privileges 表示可以对数据进行任意的操作,
-- all privileges 可以替换为 select,delete,update,create,drop

-- 修改用户的密码
update mysql.user set password=password('qweasd11') where user='joker';

-- 修改密码必须刷新才会起作用
flush privileges;

Mysql 5.7

-- 创建用户
CREATE USER 'joker'@'%' IDENTIFIED BY 'qweasd11';

-- 授权用户访问的数据库以及权限 
grant all privileges on test.* to 'joker'@'%';
-- test为访问数据库
-- all privileges 表示可以对数据进行任意的操作,
-- all privileges 可以替换为 select,delete,update,create,drop

-- 修改用户的密码
update mysql.user set authentication_string=password('qweasd11') where user='joker';

-- 修改密码必须刷新才会起作用
flush privileges;

-- 删除用户权限
revoke all privileges on test.* from 'joker'@'%';

Mysql 8

-- 创建用户
create user 'joker11'@'localhost' identified by 'Password=qweasd11';

-- 授权用户访问的数据库以及权限
grant all privileges on test.* to 'joker11'@'localhost' with grant option;
-- test为访问数据库  可以使用*表示所有的数据库
-- all privileges 表示可以对数据进行任意的操作,
-- all privileges 可以替换为 select,delete,update,create,drop

-- 取消授权
revoke all privileges on test.* from 'joker11'@'localhost';

-- 查看用户授权信息
show grants for 'joker11'@'localhost';

-- 修改用户的密码
Alter user 'joker11'@'localhost' identified by '新密码';

-- 修改密码必须刷新才会起作用
flush privileges;

-- 删除用户
drop user 'joker11'@'localhost';

注意:

如果提示设置错误,可能是因为密码强度不符合要求,在mysql 5.7 以上密码强度要求变的更加严格!

MySql 版本过低或者更高的没有测试过,如果按照上面的设置出现任何问题本人概不负责!
  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Joker_PL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值