1. 程式人生 > >安裝mysql8.0.11版本,並使用mybatis進行連線mysql遇到的問題

安裝mysql8.0.11版本,並使用mybatis進行連線mysql遇到的問題

之前Centos遠端伺服器使用mysql的版本是5.1.32,今天重新安裝了mysql的最先版本8.0.11,安裝過程出現了一些問題。

1、第一個錯誤:1251異常。

(1)安裝完mysql8.0.11之後,使用Navicat遠端連線Mysql報1251錯誤,但是ip,埠,賬號密碼都是正確的。而且在遠端伺服器上,直接使用shell命令,用賬號密碼登陸卻可以登陸。


(2)出現這個原因是mysql8 之前的版本中加密規則是mysql_native_password,而在mysql8之後,加密規則是caching_sha2_password。

(3)解決問題方法有兩種,一種是升級navicat驅動,一種是把mysql使用者登入密碼加密規則還原成mysql_native_password.。

現在介紹的是第二種方法的步驟:

mysql -uroot -p   #進入伺服器中,執行這條命令,再輸入密碼,即可進入mysql資料庫
mysql>use mysql;
mysql>ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #修改加密規則 
mysql>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; #更新一下使用者的密碼 
mysql>FLUSH PRIVILEGES; #重新整理許可權
重新連線,問題就解決了。

2、第二個錯誤:使用mybatis連線mysql,丟擲異常錯誤。

(1)異常錯誤:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

(2)錯誤原因:資料庫連線驅動的方式不適用。

(3)解決方法:使用最新的mysql連線驅動,即將`com.mysql.jdbc.Driver'改為`com.mysql.cj.jdbc.Driver'

以前版本使用的連線驅動:

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://xxx.xx.xx.xxx:3306/db?characterEncoding=utf-8
jdbc.username=root
jdbc.password=admin

解決後的資料庫連線驅動:

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://xxx.xx.xx.xxx:3306/db?characterEncoding=utf-8
jdbc.username=root
jdbc.password=admin

3、第三個警告:Establishing SSL connection without server's identity verification is not recommended

(1)警告資訊:Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

(2)警告原因:這是因為Mysql在高版本需要指明是否進行SSL連線

(3)解決方法:雖然不修改也不影響使用,但是如果想要不出現警告,可以在mysql連線字串url中加入useSSL=false或者useSSL=true即可。如下

jdbc.url=jdbc:mysql://xxx.xxx.xx.xxx:3306/db?characterEncoding=utf-8&useSSL=false