background
Some time ago, I always encountered the problem of database connection timeout. I changed the druid connection pool configuration and it still appeared. Then began to change the configuration of jdbcUrl, of course, it is still useless. Finally, the DBA changed the database configuration (max_allowed_packet), which is said to be useful. However, the production environment is performing well, and the pre-release environment is still not so good...
Speaking of the configuration of jdbcUrl, I usually copy various projects from side to side, and I haven’t read it specifically, so I’ll record it here.
Configuration
parameter
parameter | Description | Defaults | Common value |
autoReconnect | auto connect | false | true |
autoReconnectForPools | Automatic connection connection pool | false | true |
characterEncoding | When useUnicode=true, specify the character set | UTF-8 | |
allowMultiQueries | In a statement, it is allowed to use ";" to separate multiple queries | false | true |
failOverReadOnly | When failover occurs in autoReconnect mode, should the connection be set to "read-only" | true | false |
useSSL | Use SSL when communicating with the server | true | false |
useUnicode | Whether to use Unicode | false | true |
socketTimeout | When the database does not return, the waiting time (ms) is applied. Must be greater than or equal to the value of Socket TimeOut configured by the database | 0 | 60000 |
General configuration
jdbc:mysql://host:port/databaseName?useSSL=false&autoReconnect=true&autoReconnectForPools=true&allowMultiQueries=true&useUnicode=true&characterEncoding=utf8
reference
mysql JDBC URL parameter analysis
Talk about the setting of jdbc socketTimeout
Description of several important parameters in MySQL JDBC URL
In-depth understanding of JDBC timeout settings
Database timeout and socket timeout issues
Solution to error reporting of MySQL's wait_timeout connection timeout problem
MySQL classic 8-hour problem-wait_timeout
mysql reconnected, connection lost: The last packet successfully received from the server
java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more
The server time zone value'???ú±ê×??±??' is ............. in JDBC