一聚教程网:一个值得你收藏的教程网站

热门教程

详解关于MySQL 8.0走过的坑

时间:2022-06-29 09:15:00 编辑:袖梨 来源:一聚教程网

今天手贱更新了MySQL 8.0

第一个问题:Navicat连接不上数据库

安装的mysql为localhost:3306,配置一切默认,安装后打开Navicat 12 新建连接,直接报错

authentication plugin 'caching_sha2_password'

 

身份验证插件不能被加载

查了下官方文档6.5.1.3 Caching SHA-2 Pluggable Authentication

原来在MySQL 8.0中,caching_sha2_password取代了mysql_native_password成为默认的身份验证插件,官方给出的解决方案如下

1、重新配置服务器以恢复到以前的默认身份验证插件(mysql_native_password)。

[mysqld]
default_authentication_plugin=mysql_native_password

该设置允许8.0之前的客户端连接到8.0服务器,但是,该设置应被视为临时设置,而不是长期或永久性解决方案,因为它会导致使用有效设置创建的新帐户放弃提供的改进的身份验证安全性 caching_sha2_password。

2、将根管理帐户的身份验证方式更改为mysql_native_password。

对于新的MySQL 8.0安装,在初始化数据目录时,将创建帐户'root'@'localhost',并且该帐户将默认使用caching_sha2_password。连接到服务器root并使用ALTER USER 如下更改帐户身份验证插件和密码:

ALTER USER 'root'@'localhost'
 IDENTIFIED WITH mysql_native_password
 BY 'password';

至此,解决了MySQL 8.0的默认身份校验更换问题。

第二个问题:Caused by: java.sql.SQLException: Unknown initial character set index '255'...

在更新完数据库后,本地启了一个java小工程,连接数据库跑了个测试程序直接抛出异常,叕查了一下官方文档 Changes in MySQL 8.0.1 (2017-04-10, Development Milestone) ,原来是8.0.1的版本将Unicode字符集支持中进行了几项重要更改,默认字符集已从更改latin1为 utf8mb4。而这个这个系统默认 collation_server 和 collocation_database 系统变量由 latin1_swedish_ci 变为 utf8mb4_0900_ai_ci。

解决办法:所有这些更改都已经在新版本的MySQL连接器Java中进行了处理,不需要配置MySQL。所以只需要升级MYSQL的版本即可,将5.1.6更改为5.1.44,问题完美解决。


    mysql
    mysql-connector-java
    5.1.44
   

问题三安装完成后进入数据库show databases;、或者尝试更改权限时报错

ERROR 1449 (HY000): The user specified as a definer ('mysql.infoschema'@'localhost') does not exist
Table 'mysql.role_edges' doesn't exist

解决方法

mysql_upgrade -u root -p;

问题四:在客户端成功连接数据库之后,发现项目里的pdo连接mysql又报错了。

Next PDOException: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client [caching_sha2_password] in /vendor/yiisoft/yii2/db/Connection.php:687

这个错可能是mysql默认使用caching_sha2_password作为默认的身份验证插件,而不再是mysql_native_password,但是客户端暂时不支持这个插件导致的。官方文档说明

In MySQL 8.0, caching_sha2_password is the default authentication plugin rather than mysql_native_password. For information about the implications of this change for server operation and compatibility of the server with clients and connectors, see caching_sha2_password as the Preferred Authentication Plugin.

在MySQL 8.0中,caching_sha2_password是默认的身份验证插件,而不是mysql_native_password。有关此更改对服务器操作的影响以及服务器与客户端和连接器的兼容性的信息,请参阅caching_sha2_password作为首选身份验证插件。

解决方法

编辑my.cnf文件,更改默认的身份认证插件。

$ vi /etc/my.cnf

在[mysqld]中添加下边的代码

default_authentication_plugin=mysql_native_password

然后重启mysql

$ service mysqld restart

网站终于正常打开了。。。

热门栏目