How to close all active connections?

Asked

Viewed 5,793 times

1

I have 8 open connections in the database and would like to close all of them, is possible?

What is the Mysql command that does this?

  • Does not work mysql_close() ?

  • put the code you open the connection with Mysql

  • What exactly do you want to do?

  • I wanted to do this by giving a command in the bank and not by code, I am using the workbanch

  • 1

    mysql_close() as well as mysql_ is DEPRECATED, if using place mysqli_* in place

  • Some systems make persistent connections or try to reconnect every time the system loses connection, stay tuned for this.

  • I can’t test, so I can’t write an answer with this, but it’s worth taking a look https://www.percona.com/blog/2009/05/21/mass-killing-of-mysql-connections/

  • mysql_close() is not running

  • 1

    Where’s the tag saying the subject is about PHP? Provide more details about the language you are using, this is important for those reading the question and having to give an answer. Or is it even important to those who will have their doubt

  • 1

    It has nothing to do with PHP. OP just wants to disconnect everything world at once. a Restart solves :P hehe

  • 1

    that same rray, I just want to take down all connections, independent of system

  • @Lucassousa Take a look at [tour]. You can accept an answer if it solved your problem. You can vote for all the posts on the site as well. Did any help you more? You need something to be improved?

Show 7 more comments

1 answer

6

It does not exist directly but it is possible to do this. Run this in Mysql:

select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/a.txt';

afterward

source /tmp/a.txt;

Source.

Documentation of KILL.

You can do this too:

SELECT GROUP_CONCAT(CONCAT('KILL QUERY ',id,';') SEPARATOR ' ') KillQuery
FROM information_schema.processlist WHERE user<>'system user'\G

Source.

To rotate on the command line:

mysql -NBe "SELECT CONCAT('KILL ', id, ';') FROM information_schema.processlist WHERE user = 'some_username';" | mysql -vv

Source.

I put in the Github for future reference.

  • source is giving syntax error

  • 1

    In this link shows how to run without saving to file but yes using variables.

  • There are other options. See link of the source is doing the same.

  • are two separate commands @Lucassousa, run one and then run the other

Browser other questions tagged

You are not signed in. Login or sign up in order to post.