天天看點

Springboot整合mybatis連接配接mysql8的坑

經過一次嘗鮮mysql8,付出了慘痛代價,特整理“坑”,供後人查詢參閱。

1、安裝MySQL8時,選擇加密方式應選5.7及以前的方式。

mysql8 之前的版本中加密規則是mysql_native_password,而在mysql8之後,加密規則是caching_sha2_password。

如果你不幸選擇了,sha2,那麼參照以下方式修改:

參考:https://blog.csdn.net/weixin_42403773/article/details/80602603

把mysql使用者登入密碼加密規則還原成mysql_native_password.

這裡采用方法2解決,具體操作步驟如下:

1).打開指令行小黑屏,進入MySQL的bin目錄,然後輸入mysql -u root -p,輸入密碼

2).然後輸入

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #修改加密規則

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; #更新一下使用者的密碼

FLUSH PRIVILEGES; #重新整理權限

 2、修改JDBC的驅動jar的版本為 8.0.11及以上版本。 

Springboot整合mybatis連接配接mysql8的坑

把标紅的地方(也就是jdbc的包版)變量值,改為8.0.11(及以上)版本。

3、如果出現時區錯誤。

參考:http://www.cnblogs.com/sunny3096/p/9259274.html

異常提示如:

Could not get JDBC Connection; nested exception is java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

需要去修改連結字元串,或者修改mysql的時區。

方式一:修改資料庫url

jdbc:mysql://localhost:3306/springsecurity?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
           

方式二:修改資料庫時區

set global time_zone='+8:00';
           

這樣,mybatis連接配接mysql8就可以正常使用了

繼續閱讀