使用“plugin:auth_socket”更改MySQL5.7中的用户密码

编程

假设您安装5.7并且未指定密码。您将看到以下内容:

1

2

3

4

5

SELECT User, Host, HEX(authentication_string) FROM mysql.user;

+-----------+-----------+------------------------------------------------------------------------------------+

| User      | Host      | HEX(authentication_string)                                                         |

+-----------+-----------+------------------------------------------------------------------------------------+

| root      | localhost |                                                                                    |

密码为空。我们更改它:

1

2

3

4

5

6

7

mysql> ALTER USER "root"@"localhost" IDENTIFIED BY "test";

 

mysql> SELECT User, Host, HEX(authentication_string) FROM mysql.user;

+-----------+-----------+------------------------------------------------------------------------------------+

| User      | Host      | HEX(authentication_string)                                                         |

+-----------+-----------+------------------------------------------------------------------------------------+

| root      | localhost |                                                                                    |

这不起作用,它仍然是空的:

1

2

3

4

5

6

7

mysql> SET PASSWORD FOR "root"@"localhost" = PASSWORD("test");

 

mysql> SELECT User, Host, HEX(authentication_string) FROM mysql.user;

+-----------+-----------+------------------------------------------------------------------------------------+

| User      | Host      | HEX(authentication_string)                                                         |

+-----------+-----------+------------------------------------------------------------------------------------+

| root      | localhost |                                                                                    |

但为什么?我们来看看警告:

1

2

3

4

5

6

7

mysql> show warnings;

+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Level   | Code | Message                                                                                                                                                                                 |

+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Warning | 1287 | "SET PASSWORD FOR  = PASSWORD("")" is deprecated and will be removed in a future release. Please use SET PASSWORD FOR  = "" instead |

| Note    | 1699 | SET PASSWORD has no significance for user "root"@"localhost" as authentication plugin does not support it.                                                                              |

+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

问题出在1699号注释中。该用户使用的是不支持密码的身份验证插件。可能是哪一个

1

2

3

4

5

6

7

mysql> SELECT * from user where User="root"G

*************************** 1. row ***************************

                  Host: localhost

                  User: root

[...]

                plugin: auth_socket

[...]

好的, auth_socket。如果您安装5.7并且没有为root用户提供密码,它将使用auth_socket插件。该插件不关心,也不需要密码。它只检查用户是否使用UNIX套接字进行连接,然后比较用户名。

如果我们要配置密码,我们需要在同一命令中同时更改插件并设置密码。首先更改插件然后设置密码将不起作用,它将再次回退到auth_socket。所以,运行:

因此,正确的方法是运行以下命令:

1

ALTER USER "root"@"localhost" IDENTIFIED WITH mysql_native_password BY "test";

 

1

2

3

4

5

mysql> SELECT User, Host, HEX(authentication_string) FROM mysql.user;

+-----------+-----------+------------------------------------------------------------------------------------+

| User      | Host      | HEX(authentication_string)                                                         |

+-----------+-----------+------------------------------------------------------------------------------------+

| root      | localhost | 2A39344244434542453139303833434532413146393539464430324639363443374146344346433239 |

如果您的部署使用空密码,并在以后更改它们,请记住更新脚本!

 

以上是 使用“plugin:auth_socket”更改MySQL5.7中的用户密码 的全部内容, 来源链接: utcz.com/z/515214.html

回到顶部