Site icon PrestaShop | General Knowledge

Mysql how to close all active connection

If you have MySQL administrative access, you can view and terminate active connections.

1. View active connections

SHOW PROCESSLIST;

or

SHOW FULL PROCESSLIST;

2. Kill a specific connection

Find the Id from the process list and run:

KILL 12345;

where 12345 is the connection ID.

3. Kill all sleeping connections

Generate KILL statements:

SELECT CONCAT('KILL ', id, ';')
FROM information_schema.processlist
WHERE COMMAND = 'Sleep';

Copy and execute the generated commands.

4. Kill all connections except your current session

SELECT CONCAT('KILL ',id,';')
FROM information_schema.processlist
WHERE id <> CONNECTION_ID();

On shared hosting

Many hosting providers (such as Hostinger, Bluehost, etc.) do not grant permission to kill MySQL connections. In that case:

 

Exit mobile version