mysql8.0.X安装程序是比较新的版本,最近用JAVA操作mysql8.0.X,碰到几个问题,这里记录一下:
1、报如下错:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
解决方法:需要用到新版本的驱动,比如:mysql-connector-java-8.0.12
下载地址: http://www.mvnrepository.com/artifact/mysql/mysql-connector-java/8.0.12
2、报错如下:
Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
解决方法: Mysql和mysql-connector都为8.0以上的版本时,连接驱动就不要再用:com.mysql.jdbc.Driver了,要引用com.mysql.cj.jdbc.Driver
3、报如下错:
Mon Jun 24 15:40:04 CST 2019 WARN: Establishing SSL connection without server'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 default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Exception in thread "main" java.lang.NullPointerException
8.0.X以上的版本还需在数据库名后面加上这些东西 :
?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true
由原来的:
jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8
变为如下的:
jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true