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;(最简单省力)
我个人比较建议用这个,因为这个限制的存在就是为了防止暴力破解密码.

你可能感兴趣的:(MySQL)