第一个错误:连接重试失败次数过多导致的错误
java.sql.SQLException: null, message from server: "Host '192.168.8.1' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"
使用springboot项目访问数据库,连接重试失败次数过多导致,会触发 MySQL 的保护机制
,会在 mysql 库中的 user 表中添加一条记录,host 为 localhost,意思是只允许本地连接,不允许远程连接。
使用命令查看,选择 mysql 库,查询 user 表
select host,user from user where user = 'root';
+-------------+------+
| host | user |
+-------------+------+
| % | root |
| localhost | root |
+------+-------------+
1 row in set (0.00 sec)
直接修改是不行的,报错:重复的键,不允许修改;所以只能根据条件删除一条记录
delete from user where user = 'root' and host = 'localhost';
然后再查看,只剩一条 host 为 %
的记录,这样就解决了
第二个错误:因为 MySQL 版本不兼容,导致报错
使用 VSCode 访问的时候报错:
create connection SQLException, url: jdbc:mysql://linuxhost:3306/travel, errorCode 0, state 08S01
使用 idea 访问项目的时候不会报错,会给出警告:
Fri Apr 08 20:57:03 CST 2022 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 5.5.45
版本之后必须要设置 useSSL
这个属性,所以在配置文件里设置了 useSSL=false
就解决问题了
spring.datasource.url=jdbc:mysql://linuxhost:3306/travel?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false
评论区