Technology Encyclopedia Home >The timeout setting for the MySQL connection in the cloud database is too short. How can I increase the time?

The timeout setting for the MySQL connection in the cloud database is too short. How can I increase the time?

To increase the timeout setting for a MySQL connection in a cloud database, you typically need to adjust the wait_timeout and interactive_timeout parameters in the database configuration. These parameters control how long the server waits for activity on a connection before closing it.

Steps to Increase Timeout:

  1. Access the Cloud Database Console: Log in to your cloud database management interface (e.g., Tencent Cloud's TencentDB for MySQL).
  2. Modify Parameters:
    • Navigate to the Parameter Settings or Configuration Management section.
    • Locate wait_timeout and interactive_timeout (default is usually 28800 seconds, or 8 hours).
    • Increase the values (e.g., set to 604800 for 7 days) and save the changes.
  3. Restart the Database (if required): Some cloud platforms apply changes immediately, while others may require a restart.

Example:

If your application frequently experiences disconnections due to inactivity, increasing wait_timeout to 86400 (24 hours) can help maintain long-lived connections.

Tencent Cloud-Specific Solution:

In TencentDB for MySQL, you can adjust these parameters via the Console:

  1. Go to TencentDB for MySQL > Instance Management.
  2. Select your instance and click Database Management > Parameters.
  3. Search for wait_timeout and interactive_timeout, modify the values, and apply changes.

If you're using a connection pool (e.g., in Java with HikariCP or Python with SQLAlchemy), ensure the pool's idle timeout aligns with the database's wait_timeout to avoid premature disconnections.

For TencentDB, you can also use ProxySQL (if supported) to manage connection timeouts dynamically.