MySQL: Terminate idle connections

Manual cleanup:

  • Login to MySQL

    mysql -uroot -p

  • Run the following query

    select concat(‘KILL ‘,id,’;’) from information_schema.processlist where Command=’Sleep’;

  • Copy the query result, paste and remove a pipe ‘ | ‘ sign, copy, and paste all again into the query console
  • Hit ENTER

Automatic cleanup:

  • Configure mysql-server by setting a shorter timeout on wait_timeout and interactive_timeout
  • Check your existing configuration using the following command

    show variables like “%timeout%”;

  • Set with:

    set global wait_timeout=3; set global interactive_timeout=3;

2 thoughts to “MySQL: Terminate idle connections”

Leave a Reply

Your email address will not be published. Required fields are marked *