您的位置:首页 > 数据库 > MySQL

MySQL 8:连接错误信息对应

2020-03-16 18:41 489 查看

这篇文章记录一下在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即可正常动作了。

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

  • 点赞
  • 收藏
  • 分享
  • 文章举报
liumiaocn 博客专家 发布了1133 篇原创文章 · 获赞 1354 · 访问量 410万+ 他的留言板 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: