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 版本过低或者更高的没有测试过,如果按照上面的设置出现任何问题本人概不负责!