当前位置: 移动技术网 > IT编程>数据库>Mysql > 详解关于MySQL 8.0走过的坑

详解关于MySQL 8.0走过的坑

2019年05月29日  | 移动技术网IT编程  | 我要评论

今天手贱更新了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,问题完美解决。

<dependency>
    <groupid>mysql</groupid>
    <artifactid>mysql-connector-java</artifactid>
    <version>5.1.44</version>
  </dependency> 

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

error 1449 (hy000): the user specified as a definer () 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

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网