JDBC鏈接MySQL8的注意事項及說明
JDBC鏈接MySQL8的注意事項
需要使用高版本的JDBC驅(qū)動,“mysql-connector-java 8”以上版本。
1. JDBC driver 由“com.mysql.jdbc.Driver”改為“com.mysql.cj.jdbc.Driver”。
2. JDBC url為:
jdbc:mysql://localhost/rs_report?userSSL=true&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT
3. 出現(xiàn)錯誤:
“Establishing SSL connection withoutserver'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 defaultif explicit option isn't set. For compliance with existing applications notusing SSL the verifyServerCertificate property is set to 'false'. You needeither to explicitly disable SSL by setting useSSL=false, or set useSSL=trueand provide truststore for server certificate verification.”
解決方案,在url中加上“userSSL=true”或“userSSL=false”。
4. 出現(xiàn)錯誤:
“java.sql.SQLException: The server time zonevalue '???ú±ê×??±??' is unrecognized or represents more than one time zone. Youmust configure either the server or JDBC driver (via the serverTimezoneconfiguration property) to use a more specifc time zone value if you want toutilize time zone support.”
解決方案,在url中加上“serverTimezone=GMT”。
jdbc如何連接MySQL8版本
驅(qū)動包請到: https://mvnrepository.com/artifact/mysql/mysql-connector-java 下載適合自己的版本
注意事項
以下是jdbc配置,驅(qū)動包不再是 com.mysql.jdbc.Driver 類了。
連接url需要制定時區(qū),時區(qū)可以到驅(qū)動包的配置文件里找:lib/mysql-connector-java-8.0.11.jar!/com/mysql/cj/util/TimeZoneMapping.properties
driver=com.mysql.cj.jdbc.Driver #url=jdbc:mysql://localhost:3306/javaee?useSSL=false&useUnicode=true&characterEncoding=utf8 url=jdbc:mysql://localhost:3306/javaee?useSSL=false&serverTimezone=Asia/Shanghai username=root password=root
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
MySQL8.0內(nèi)存相關(guān)參數(shù)總結(jié)
這篇文章主要介紹了MySQL8.0內(nèi)存相關(guān)參數(shù)總結(jié),幫助大家更好的理解和學(xué)習(xí)mysql,感興趣的朋友可以了解下2020-08-08
SQLyog錯誤號碼MySQL?plugin?caching_sha2_password?could?not?
這篇文章主要介紹了SQLyog錯誤號碼?plugin?caching_sha2_password?could?not?be?loaded的解決方法,需要的朋友可以參考下2023-06-06
mysql 5.7以上版本安裝配置方法圖文教程(mysql 5.7.12\mysql 5.7.13\mysql 5.7.
這篇文章主要為大家分享了MySQL 5.7以上縮版本安裝配置方法圖文教程,包括mysql5.7.12、mysql5.7.13、mysql5.7.14安裝教程,包括感興趣的朋友可以參考一下2016-08-08
K8s 如何部署 MySQL 8.0.20 主從復(fù)制結(jié)構(gòu)
這篇文章主要介紹了K8s 如何部署 MySQL 8.0.20 主從復(fù)制結(jié)構(gòu),本次使用 OpenEBS 來作為存儲引擎,OpenEBS 是一個開源的、可擴展的存儲平臺,它提供了一種簡單的方式來創(chuàng)建和管理持久化存儲卷,需要的朋友可以參考下2024-04-04

