目前有需求是在两个mysql数据库间同步数据,采用的方案是先利用maxwell将源数据库的log_bin日志传到kafka,再从kafka消费到目的数据库,但最近发现日志中总是报这么个warn:

[13:43:53:135] [WARN] - com.zaxxer.hikari.pool.PoolBase.isConnectionAlive(PoolBase.java:176) \
- Dataxxxx - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@4fda9dd2 \
(No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.

其中的Dataxxxx中的xxxx是数据库端口号。根据日志中提示,应该是maxlifetime值太大,看项目中配置是默认的180000,而数据库的interactiv_timeout和wait_timeout都为30。于是乎,先只修改了maxlifetime。

spring.datasource.hikari.max-lifetime=20

然后重新打包运行,发现还是会报同样warn,后来参考其他帖子说maxlifetime小于数据库配置参数timeout应该不少于30,于是再次将以上两个值改为300。改后如下:

mysql> show variables like "%timeout%";
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 20       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 300      |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 3600     |
| wait_timeout                | 300      |
+-----------------------------+----------+
13 rows in set (0.00 sec)

之后再运行程序就没问题了。

更多推荐

kafka同步mysql数据报Possibly consider using a shorter maxLifetime value.