mysql8使用grant授权修改

在使用mysql5的时候,在linux安装完成mysql后,习惯使用grant all privileges on *.* to 'user'@'%';命令授权远程连接操作。

最近linux安装mysql8后,再次使用这个命令,会有如下错误:

ERROR 1410 (42000): You are not allowed to create a user with GRANT

看了mysql的官方文档,原来这个特性被移除了,下面看文档说明:

Using GRANT to modify account properties other than privilege assignments. This includes
authentication, SSL, and resource-limit properties. Instead, establish such properties at account-creation
time with CREATE USER or modify them afterward with ALTER USER.

使用grant修改账户权限分配以外的账户属性。包括认证,SSL,和资源限制配置等。取而代之的是创建用户create user或者创建后修改alter user的方式。

查mysql.user表:select host,user from user:

此时我们进行操作的是root,它的host为:localhost

我们使用grant all on *.* to 'root'@'localhost' 是可以成功的,但此时仍无法远程登陆。

可以使用以下方式:

1.alter user set user.host='%' where user.user='root',此时印证官方doc说的使用alter user

2.create user 'userName'@'%' identified ...,创建新用户,此时使用create user

mysql8使用grant授权修改_第1张图片

然后就可以远程了。注释下:'userName'@'%',%表示允许所有远程的地址。

The following features related to account management have been removed:

IDENTIFIED BY PASSWORD 'hash_string' syntax for CREATE USER and GRANT. Instead,
use IDENTIFIED WITH auth_plugin AS 'hash_string' for CREATE USER and ALTER
USER, where the 'hash_string' value is in a format compatible with the named plugin.
The PASSWORD() function. Additionally, PASSWORD() removal means that SET PASSWORD ...
= PASSWORD('auth_string') syntax is no longer available.
Using GRANT to create users. Instead, use CREATE USER. Following this practice makes the
NO_AUTO_CREATE_USER SQL mode immaterial for GRANT statements, so it too is removed.

其中首次登陆的mysql会强制修改密码,之前的操作是:set password = password("pwd")

现在直接使用set password = "pwd"即可

 

mysql8密码加密方式的更改:

之前默认是mysql_native_password,现在改为caching_sha2_password。很多连接工具,像nivacat12,仍然使用默认的mysql_native_password,所以在连接的时候回报错:

1251:Client does not support authentication protocol requested by server; consider upgrading
MySQL client

此时需要将mysql.user表中的plugin字段修改下:

ALTER USER user IDENTIFIED WITH mysql_native_password BY 'password';

或者等待连接工具升级支持吧

你可能感兴趣的:(mysql)