1 数据库连接异常
o.s.b.a.j.DataSourceHealthIndicator - DataSource health check failed
org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
ERROR c.alibaba.druid.pool.DruidDataSource - create connection SQLException, url: jdbc:mysql://172.17.1.165:3306/face_recognition?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8, errorCode 0, state 08S01
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
2 查询的原因
- 查看连接时间
mysql> show global variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
数据库连接池耗尽。
- 最大连接数
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
- 查看连接池数量
mysql> show full processlist;
+----+------+-----------+------+---------+------+----------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+----------+-----------------------+
| 4 | root | localhost | NULL | Query | 0 | starting | show full processlist |
+----+------+-----------+------+---------+------+----------+-----------------------+
- 查看线程数
mysql> show status like 'Threads';
Empty set (0.00 sec)
3 问题再现
- 服务器IP变更,
- 微服务注册中心等系列服务都进行了修改
- 并通过docker将微服务一一重启,
- 但是,就是连接不了数据库。
排查了一天,最后,发现是Docker内无法连接网络,因为服务器IP变更,Docker仍使用之前服务器的IP配置,所以Docker内所有的服务均无法连接网络。 - 方案
重启Docker,重启Docker中的所有服务即可。
[2]https://blog.csdn.net/qq_40651609/article/details/86756200?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase
[3]https://blog.csdn.net/qq_40651609/article/details/86756200?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase
[4]https://blog.csdn.net/java1949java/article/details/94580585?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase
[5]https://blog.csdn.net/ClearLoveQ/article/details/81479001?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2allfirst_rank_v2~rank_v25-5-81479001.nonecase&utm_term=08s01%20state%20数据库链接
[6]https://www.zhihu.com/question/343352928/answer/806828168
[7]https://www.cnblogs.com/niunafei/p/12824859.html
[8]https://blog.csdn.net/whxwkb/article/details/84110703
[9]http://blog.chinaunix.net/uid-20382003-id-3022768.html
[10]https://www.jb51.net/article/111531.htm