新版MySQL8.0.12中,添加用户并设定权限
MySQL8.0之前在添加用户的时候可以直接设置用户权限如:
GRANT ALL ON *.* TO `zqj`@`ip` IDENTIFIED BY 'passowrd' WITH GRANT OPTION;
但是在新版MySQL中这样就会报错,必须分开开,先创建用户,然后才能设置权限如下:
CREATE USER `zqj`@`ip` IDENTIFIED BY 'zqj' [PASSWORD EXPIRE INTERVAL 90 DAY];
GRANT ALL ON *.* TO `zqj`@`127.0.0.1` WITH GRANT OPTION;
CREATE USER 'user1'@'%' IDENTIFIED BY '07fa533360d9';
如
CREATE USER 'yunwei01'@'%' IDENTIFIED BY 'yunwei01';
'%' - 所有情况都能访问 'localhost' - 本机才能访问 '111.222.33.44' - 指定 ip 才能访问
注:修改密码
update mysql.user set password=password('新密码') where user='user1';
grant all privileges on 想授权的数据库.* to 'user1'@'%';
如:
GRANT all PRIVILEGES on zldc.* to 'yunwei01'@'%';
flush privileges;
all 可以替换为 select,delete,update,create,drop
show grants for test;