需要使用高版本的JDBC驱动,“mysql-connector-java 8”以上版本。
1. JDBC driver 由“com.mysql.jdbc.Driver”改为“com.mysql.cj.jdbc.Driver”。
2. JDBC url为:
jdbc:mysql://localhost/rs_report?useSSL=true&useUnicode=true&characterEncoding=UTF8&serverTimezone=UTC
3. 出现错误:“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中加上“useSSL=true”或“useSSL=false”。
4. 出现错误:“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.”
新版mysql驱动的url必须设置时区,即serverTimezone=UTC,否则会出现报错:
解决方案,在url中加上“serverTimezone=UTC”。
5、Communications link failure
长时间空闲被MySQL干掉了连接,但是连接池认为你还连着,给MySQL延长等待时间my.cnf中加入如下参数
wait_timeout=606024365 --自己衡量
interactive_timeout=606024365
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;(最简单省力)
我个人比较建议用这个,因为这个限制的存在就是为了防止暴力破解密码.
参考:https://blog.csdn.net/shareye1992/article/details/83652265