1. 程式人生 > >安裝連線mysql8時候遇到的問題以及解決(轉)

安裝連線mysql8時候遇到的問題以及解決(轉)

官網下載mysql8的安裝包:

https://dev.mysql.com/downloads/

下一步安裝即可。

mysql8增加了傳說中的安全性校驗

遇到的幾個問題:

1、natcat連線不上。參考連結:https://blog.csdn.net/weixin_42181147/article/details/80360151

必須執行下面兩個步驟,缺一不可。

一、        mysql8.0加密方式與mysql5幾加密方式不同,需要先更改加密方式。

1.   更改加密方式

ALTERUSER 'root'@'localhost' IDENTIFIED BY 'password' [a1] PASSWORDEXPIRE NEVER;

2.   更改密碼

ALTERUSER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';[a2] 

 [a1]你的root使用者密碼

 [a2]你的root使用者密碼

二、        修改root許可權。可解決navicat連線mysql時報1130錯誤。

1.修改user表中root的許可權:Update user set host = ‘%’ whereuser = ‘root’;

2.在檢視user表:select user,host from user;

3.更新表:flushprivileges;

也可以在mysql安裝的時候安全性選擇上選mysql5的特徵

然後idea配置mybatis-generator的配置

發現mysql8的驅動改了,變為:

com.mysql.cj.jdbc.Driver
執行報錯,什麼ssl連結方式的警告,解決方式:
jdbc:mysql://localhost:3306/testweb?useSSL=false
加引數指定一下。

然後有報時區不一致啥問題。參考連結:https://blog.csdn.net/weixin_41908757/article/details/80283015
1、錯誤原因:
使用原mysql5.1.38不會出現該問題
因使用了Mysql最新版驅動所以報錯

2、解決方案:
方案1、在專案程式碼
-資料庫連線URL後,加上 (注意大小寫必須一致) ?serverTimezone=UTC 方案2、在mysql中設定時區,預設為SYSTEM set global time_zone='+8:00'

Sun Mar 19 20:51:50 CST 2017 WARN: 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.

從警告資訊中可以看出,5.5.45+、5.6.26+ 和 5.7.6+ 版本預設 SSL 連線,除非特別指定不需要 SSL 連線,最好在 JDBC URL 中指明連線方式:

String jdbcUrl = "jdbc:mysql:///test?useSSL=false";

首先,我居然不能用navicat客戶端連線上mysql8.0資料庫報1251錯誤,這個的解決方式已經在我的上一篇部落格中解決了。然後我又遇到了java無法連線mysql資料庫8.0的問題。

報錯: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.

Wed May 09 16:25:23 CST 2018 WARN: 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.

    上面這段報錯中加粗的文字很重要,她告訴你mysql8.0和之前版本的區別,首先驅動換了,不是com.mysql.jdbc.Driver而'com.mysql.cj.jdbc.Driver',此外mysql8.0是不需要建立ssl連線的,你需要顯示關閉。最後你需要設定CST。所以我們需要在之前我們熟悉的java連線資料庫程式碼的基礎之上改動以下兩行程式碼:

  1. Class.forName("com.mysql.cj.jdbc.Driver");  
  2. Class.forName("com.mysql.jdbc.Driver");  
  3. conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_demo?useSSL=false&serverTimezone=UTC","root","password");  
  4.   conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_demo","root","password");  
改動完了之後你就可以成功連上mysql資料庫資料庫8.0了。

注意:

  1. Class.forName("com.mysql.cj.jdbc.Driver");  
驅動jar包用最新的才能使用連線池。