I see a lot of connections are open and remain idle for a long time, say 5 minutes.
Is there any solution to terminate / close it from server without restarting the mysql service?
I am maintaining a legacy PHP system and can not close the connections those are established to execute the query.
Should I reduce the timeout values in my.cnf file those defaults to 8 hours?
# default 28800 seconds interactive_timeout=60 wait_timeout=60
The quickest way to kill all MySQL connections would be to simply restart the MySQL service. This can be done via "Restart Services" in WHM, or via the command-line. It is also possible to kill individual connections for the MySQL client. You can access this client by issuing the MySQL command from a root SSH session.
To modify or delete a connection, start MySQL Connections Manager and select an existing connection. You can modify any of the settings by overwriting the existing values with new ones. The connection may be modified or deleted only if no active editor for its objects is opened; otherwise, you may lose your data.
Explicitly closing open connections and freeing result sets is optional. However, it's a good idea to close the connection as soon as the script finishes performing all of its database operations, if it still has a lot of processing to do after getting the results.
To prevent these connections being automatically closed, the connector can be configured to keep the connection alive by submitting a simple SELECT statement (actually SELECT 'KEEP_ALIVE';) periodically to ensure that the MySQL timeout is not reached and the connection closed.
You can KILL the processid.
mysql> show full processlist; +---------+------------+-------------------+------+---------+-------+-------+-----------------------+ | Id | User | Host | db | Command | Time | State | Info | +---------+------------+-------------------+------+---------+-------+-------+-----------------------+ | 1193777 | TestUser12 | 192.168.1.11:3775 | www | Sleep | 25946 | | NULL | +---------+------------+-------------------+------+---------+-------+-------+-----------------------+ mysql> kill 1193777;
But:
Or you configure your mysql-server by setting a shorter timeout on wait_timeout
and interactive_timeout
mysql> show variables like "%timeout%"; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | connect_timeout | 5 | | delayed_insert_timeout | 300 | | innodb_lock_wait_timeout | 50 | | interactive_timeout | 28800 | | net_read_timeout | 30 | | net_write_timeout | 60 | | slave_net_timeout | 3600 | | table_lock_wait_timeout | 50 | | wait_timeout | 28800 | +--------------------------+-------+ 9 rows in set (0.00 sec)
Set with:
set global wait_timeout=3; set global interactive_timeout=3;
(and also set in your configuration file, for when your server restarts)
But you're treating the symptoms instead of the underlying cause - why are the connections open? If the PHP script finished, shouldn't they close? Make sure your webserver is not using connection pooling...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With