1. 程式人生 > >JDBC連線MySQL8.0.x注意事項

JDBC連線MySQL8.0.x注意事項

1.連線類(會導致Could not create connection to database server異常.)

com.mysql.jdbc.Driver
變為(包路徑多了.cj)
com.mysql.cj.jdbc.Driver

2.Establishing SSL connection withoutserver’s identity verification is not recommended.

在連線url後面追加“&useSSL=true”或“&useSSL=false”

3.Path does not chain with any of the trust anchors

“&useSSL=true”改成“&useSSL=false”

4.Communications link failure

這個比較複雜一些,有可能是沒有遠端許可權

長時間空閒被MySQL幹掉了連線,但是連線池認為你還連著,給MySQL延長等待時間my.cnf中加入如下引數
wait_timeout=606024365 --自己衡量
interactive_timeout=60
6024365

5.The server time zonevalue ‘???ú±ê×??±??’ is unrecognized or represents more than one time zone

需要指定時區,連線url後面追加"$serverTimezone=GMT"或者

6.不能在任意地方使用mysql -uroot -p

這個其實不是8.x的特有問題.修改/etc/profile檔案,在檔案末尾新增

PATH=/usr/local/mysql/bin:$PATH
export PATH

7.java.lang.UnsupportedClassVersionError: com/mysql/cj/jdbc/Driver Unsupported major.minor version 52.0

jdbc包的jsk版本號要求和專案編譯版本不匹配
使用mysql-connector-java 8.0.x版本,不支援1.8以下的jdk,需要升級專案的編譯版本到1.8.
如果使用MySQL5.x的可以考慮降到JDK1.7版本和5.0驅動
匹配關係:
1、jdk7+老版5.0驅動com/mysql/jdbc/Driver
2、jdk8+新版6.0驅動com/mysql/cj/jdbc/Driver

8.MySql Host is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’

同一個ip在短時間內產生太多(超過mysql資料庫max_connect_errors的最大值)中斷的資料庫連線而導致的阻塞;

1、提高允許的max_connection_errors數量:
mysql>show variables like ‘%max_connect_errors%’;
mysql>set global max_connect_errors = 1000;
mysql>show variables like ‘%max_connect_errors%’;
還可以在my.cnf修改或者新增:max_connect_errors = 1000
2.mysql>flush hosts;(最簡單省力)
我個人比較建議用這個,因為這個限制的存在就是為了防止暴力破解密碼.