詳解關於MySQL 8.0走過的坑

這篇文章主要介紹了詳解關於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

該設置允許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 ('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

網站終於正常打開了。。。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持神馬文庫。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章