Spring中连接mysql8.0.13报的错和解决方法

文章目录

    • 错误1:连接MySQL报错Unable to load authentication plugin 'caching_sha2_password'
    • 错误2: Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
    • **解决方法:** 将数据配置文件里jdbc.driver=com.mysql.jdbc.Driver这一条修改为 jdbc.driver=com.mysql.cj.jdbc.Driver
    • 错误3: 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.
    • 错误4:Unknown system variable 'query_cache_size'
    • 错误5: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone

错误1:连接MySQL报错Unable to load authentication plugin ‘caching_sha2_password’

在Spring中通过JDBC连接MySQL报错
在网上搜索后发现是由于MySQL在8.0后验证方式由mysql_native_password变为caching_sha2_password,所以连接时会报这个错。

解决方法:
在命令行中进入mysql后运行

    alter user root@localhost identified with mysql_native_password by 'password';

错误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.

解决方法:
将数据配置文件里jdbc.driver=com.mysql.jdbc.Driver这一条修改为
jdbc.driver=com.mysql.cj.jdbc.Driver

错误3: 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.

是Mysql数据库的SSL连接问题,提示警告不建议使用没有带服务器身份验证的SSL连接,是在MYSQL5.5.45+, 5.6.26+ and 5.7.6+版本中才有的这个问题。解决办法在警告中已经说明了:
解决方法:
1.在数据库连接的url中添加useSSL=false;2.url中添加useSSL=true,并且提供服务器的验证证书。如果只是做一个测试的话,没必要搞证书那么麻烦啦,在连接后添加一个useSSL=false即可,例如:

jdbc:mysql://localhost:3306/test?useSSL=false

错误4:Unknown system variable ‘query_cache_size’

原因是mysql-connector-java的版本还是6.0.6
解决方法:
升级版本到8.0.11 ,这个报错就不存在了


错误5: The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or represents more than one time zone

解决方法:
输入命令:show variables like ‘%time_zone%’;(注意是英文状态下)
Spring中连接mysql8.0.13报的错和解决方法_第1张图片
命令:set global time_zone=’+8:00’;
Spring中连接mysql8.0.13报的错和解决方法_第2张图片


你可能感兴趣的:(Java,mysql)