MySQL,8:连接错误信息对应x

发布时间:2020-10-05 来源: 精准扶贫 点击:

 MySQL 8 :连接错误信息对应 这篇文章记录一下在 MacOS 的 Catalina 版本下使用 MacOS 下安装的 MySQL 8 在进行客户端连接时所碰到的问题。

 环境说明 • 操作系统版本: 10.15.2 liumiaocn:target liumiao$ sw_vers

 ProductName:

 Mac OS X

 ProductVersion: 10.15.2

 BuildVersion:

  19C57

 liumiaocn:target liumiao$

 • MySQL 版本: 8.0.11 liumiaocn:target liumiao$ mysql -uroot -p

 Enter password:

 Welcome to the MySQL monitor.

 Commands end with ; or \g.

 Your MySQL connection id is 46

 Server version: 8.0.11 Homebrew

  Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

  Oracle is a registered trademark of Oracle Corporation and/or its

 affiliates. Other names may be trademarks of their respective

 owners.

  Type "help;" or "\h" for help. Type "\c" to clear the current input statement.

  mysql>

 • MySQL 运行状态 liumiaocn:target liumiao$ mysql.server status

  SUCCESS! MySQL running (4633)

 liumiaocn:target liumiao$

 问题现象 使用 MySQL Workbench 的如下配置

 点击 Test Connection 时,提示如下错误信息

 原因 MySQL 8 中的认证方式发生了变化

 使用如下 SQL 即可确认当前 root 用户的认证方式:

 mysql> SELECT Host, User, plugin from mysql.user;

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

 | Host

 | User

  | plugin

 |

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

 | localhost | mysql.infoschema | mysql_native_password |

 | localhost | mysql.session

 | mysql_native_password |

 | localhost | mysql.sys

 | mysql_native_password |

 | localhost | root

  | caching_sha2_password |

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

 4 rows in set (0.00 sec)

  mysql>

 对应方法 最简单的方式莫过于直接修改,比如使用如下 SQL 即可 mysql> ALTER USER "root"@"localhost" IDENTIFIED WITH mysql_native_password BY "liumiao123";

 Query OK, 0 rows affected (0.03 sec)

  mysql>

 确认完之后再次确认结果 mysql> SELECT Host, User, plugin from mysql.user;

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

 | Host

 | User

  | plugin

 |

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

 | localhost | mysql.infoschema | mysql_native_password |

 | localhost | mysql.session

 | mysql_native_password |

 | localhost | mysql.sys

 | mysql_native_password |

 | localhost | root

  | mysql_native_password |

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

 4 rows in set (0.00 sec)

  mysql>

 当然,直接修改 MySQL 的配置文件,然后重新启动也可以设定成功,而且设定会持久保存。

 [mysqld]

 default_authentication_plugin=mysql_native_password

 结果确认 此时使用 MySQL Workbench 再次连接,Test Connection 即可正常动作了。

 正确输入上述修改的密码之后,即可显示连接成功了。

相关热词搜索:错误信息 连接 MySQL

版权所有 蒲公英文摘 www.zhaoqt.net