Terminating Idle MySQL Connections: Troubleshooting
Persistent MySQL connections can accumulate over time, particularly if they remain idle for extended periods. One solution is through manual cleanup, where you can identify and terminate idle processes using the KILL command. However, this approach can lead to errors in the PHP application or webserver.
Alternatively, you can configure MySQL to automatically handle idle connections by adjusting the wait_timeout and interactive_timeout parameters. For example, setting both values to 3 ensures that idle connections are terminated after 3 seconds. You can modify these values in the MySQL configuration file and set them using the SET command.
Caution: This solution addresses the symptom rather than the root cause. It's important to investigate why connections remain open even after the PHP script has completed. Connection pooling in the webserver may be the underlying issue.
The above is the detailed content of How to Stop Persistent MySQL Connections From Draining Resources?. For more information, please follow other related articles on the PHP Chinese website!