jdbc接続mysql 8のいくつかのピット

1041 ワード

1、ドライバパッケージをmysql-connector-java-8.0.11にアップグレードする.jar
 
2、JDBC driverは「com.mysql.jdbc.Driver」から「com.mysql.cj.jdbc.Driver」に変更
 
3、urlに「userSSL=false」を付ける.次のエラーが発生します.
“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.”
 
4、urlに「serverTimezone=GMT%2 B 8」(GMT%2B8は東八区を表す)を加える
または、データベースのデフォルトタイムゾーンを直接変更します.
show variables like '%time_zone%';
set global time_zone='+8:00';

最終添付例URL:
jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&userSSL=false&serverTimezone=GMT%2B8