Mysql8.0赋予用户对数据库的全部权限相较于Mysql5.7的改动

Mysql5.7创建用户并赋予用户对数据库的全部权限

#建新用户user,新用户密码为PASSword123.
mysql>create user "user"@"localhost"identified by 'PASSword123.';
#赋予用户对数据库wordpress的全部权限
mysql>grant all privileges on wordpress.* to 'user'@'localhost' identified by 'PASSword123.';
#使配置生效。
mysql>flush privileges;
#退出MySQL。
mysql>exit;

MySQL 8.0 继续使用Mysql5.7授权语句报错信息提示如下:

mysql> grant all privileges on wordpress.* to 'user'@"localhost" identified by 'PASSword123.';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'PASSword123.'' at line 1

MySQL 8.0 正确授权语句

#创建用户
 mysql> create user 'user'@"localhost" IDENTIFIED BY 'PASSword123.';
#授权
mysql> grant all on wordpress.* to "user"@"localhost" with grant option;
#使配置生效。
mysql>flush privileges;
#退出MySQL。
mysql>exit;

主要原因
在 MySQL 8.0 中,caching_sha2_password 是默认的身份验证插件而不是之前版本的 mysql_native_password,默认的密码加密方式由之前的 SHA1 改为了 SHA2

详细解释请参考MySQL8.0用户和角色管理入门

猜你喜欢

转载自blog.csdn.net/qq_35866846/article/details/105763502