解决方式:增加 testWhileIdle=true&autoReconnect=true&validationQuery=SELECT 1
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true&testWhileIdle=true&autoReconnect=true&validationQuery=SELECT 1
-
testWhileIdle=true
:表示在连接池中的连接空闲时,是否进行连接测试。如果启用了这个选项,则当一个连接在一段时间内没有被使用时,连接池会自动对该连接进行测试,以检查连接是否仍然有效。如果连接无效,则会将其从连接池中移除。这可以避免应用程序使用无效的连接,从而提高应用程序的可靠性和稳定性。 -
autoReconnect=true
:表示在发生连接断开或失败时,是否自动重新连接。如果启用了这个选项,则当连接断开或失败时,连接池会尝试自动重新连接。这可以避免应用程序出现异常情况,从而提高应用程序的可靠性和稳定性。 -
validationQuery=SELECT 1
:表示连接测试时执行的 SQL 查询语句。如果启用了testWhileIdle
或testOnBorrow
选项,则连接池会使用这个 SQL 查询语句来测试连接的有效性。通常情况下,这个 SQL 查询语句只需要返回一个结果集,例如SELECT 1
或SELECT 'x'
等,不需要实际查询数据库。如果连接测试失败,则连接会被标记为无效并从连接池中移除
- Communications failure MySQL linkcommunications failure mysql link mysql communicationsexception jdbc communications sqlexception temporary failure mysql communications communicationsexception communications exceptions communications milliseconds successfully received cjcommunicationsexception communications exceptions communications callmanager unified manager privacy-preserving communications aggregation communications collective library nvidia