详解关于MySQL 8.0走过的坑
今天手贱更新了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
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';
第二个问题: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>
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;
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
default_authentication_plugin=mysql_native_password
$ service mysqld restart
更多相关文章
- MySQL系列多表连接查询92及99语法示例详解教程
- Linux下MYSQL 5.7 找回root密码的问题(亲测可用)
- MySQL 什么时候使用INNER JOIN 或 LEFT JOIN
- Android(安卓)- Manifest 文件 详解
- Android的Handler机制详解3_Looper.looper()不会卡死主线程
- Selector、shape详解(一)
- android2.2资源文件详解4--menu文件夹下的菜单定义
- android从服务器下载文件(php+apache+win7+MySql)
- Android发送短信方法实例详解