"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Effectively Terminate Idle MySQL Connections and Avoid Performance Issues?

How to Effectively Terminate Idle MySQL Connections and Avoid Performance Issues?

Published on 2024-12-23
Browse:194

How to Effectively Terminate Idle MySQL Connections and Avoid Performance Issues?

How to Terminate Idle MySQL Connections

Problem Scenario:

Databases can accumulate a significant number of idle connections that remain open for extended periods. This can lead to resource consumption and performance issues.

Manual Cleanup:

One approach is manual termination of idle processes. To identify open connections, use the SHOW FULL PROCESSLIST command. You can then kill the process with KILL [process_id].

However, this method has limitations:

  • It may cause errors in PHP applications or webservers.
  • It does not address the underlying cause of idle connections.

Automatic Cleaner Service:

A more comprehensive solution is to configure the MySQL server with shorter timeouts for idle connections. Edit the my.cnf file and adjust the following parameters:

wait_timeout=3
interactive_timeout=3

With these settings, MySQL will automatically terminate idle connections after 3 seconds.

Considerations:

While this approach is effective, it's important to investigate the root cause of idle connections. Issues like PHP connection pooling can contribute to this problem and should be addressed.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3