这篇文章记录一下在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即可正常动作了。
正确输入上述修改的密码之后,即可显示连接成功了。