mysql8.x 新版本jdbc连接方式

需要使用高版本的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=60
6024365

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

           https://blog.csdn.net/woshixlhm/article/details/80540881

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

独步秋风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值