# Why pt-kill hangs in connecting  to MySQL?

**URL:** <https://forums.percona.com/t/why-pt-kill-hangs-in-connecting-to-mysql/3957>\
**Category:** Percona Toolkit\
**Created:** [December 18, 2014, 9:28pm UTC](https://forums.percona.com/t/why-pt-kill-hangs-in-connecting-to-mysql/3957 "2014-12-18T21:28:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leafonsword](https://avatars.discourse-cdn.com/v4/letter/l/85f322/32.png) [@leafonsword](https://forums.percona.com/u/leafonsword)\
**Post date:** [December 18, 2014, 9:28pm UTC](https://forums.percona.com/t/why-pt-kill-hangs-in-connecting-to-mysql/3957/1 "2014-12-18T21:28:37Z")

</div>

I could connect to local MySQL successfully:

```auto
gf&#64;li741-164 ~> mysql -uroot -S /run/mysqld/mysqld.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 202
Server version: 5.6.21-70.1 Source distribution

Copyright (c) 2009-2014 Percona LLC and/or its affiliates
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

```

but when using pt-kill,it seems hangs to connect to MySQL,I waited for 5 minutes ,but it still hangs:

```auto
gf&#64;li741-164 ~> pt-kill --busy-time 6 --user root --print --socket /run/mysqld/mysqld.sock

```

---

<div class="post-metadata">

**Author:** ![scott.nemes](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/scott.nemes/32/5_2.png) [@scott.nemes](https://forums.percona.com/u/scott.nemes)\
**Post date:** [December 18, 2014, 9:36pm UTC](https://forums.percona.com/t/why-pt-kill-hangs-in-connecting-to-mysql/3957/2 "2014-12-18T21:36:28Z")

</div>

Hi leafonsword;

Do you know if there were actually any queries running for over 6 seconds during that time period? I do not believe there is any output from the tool unless pt-kill sees a query that meets the --busy-time you specify.

-Scott

---

<div class="post-metadata">

**Author:** ![leafonsword](https://avatars.discourse-cdn.com/v4/letter/l/85f322/32.png) [@leafonsword](https://forums.percona.com/u/leafonsword)\
**Post date:** [December 18, 2014, 9:52pm UTC](https://forums.percona.com/t/why-pt-kill-hangs-in-connecting-to-mysql/3957/3 "2014-12-18T21:52:08Z")

</div>

> [@scott.nemes;28721](#):
>
> Hi leafonsword;
> 
> Do you know if there were actually any queries running for over 6 seconds during that time period? I do not believe there is any output from the tool unless pt-kill sees a query that meets the --busy-time you specify.
> 
> -Scott

There is actually an uncommitted long running transaction when pt-kill executes:

```auto
mysql> show processlist;
+-----+------+-----------------+------+---------+------+-------+------------------+-----------+---------------+
| Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined |
+-----+------+-----------------+------+---------+------+-------+------------------+-----------+---------------+
| 195 | root | localhost:31769 | test | Sleep | 1710 | | NULL | 3 | 3 |
| 203 | root | localhost | NULL | Sleep | 1 | | NULL | 0 | 0 |
| 204 | root | localhost | NULL | Query | 0 | init | show processlist | 0 | 0 |
+-----+------+-----------------+------+---------+------+-------+------------------+-----------+---------------+
3 rows in set (0.00 sec)

```

---

<div class="post-metadata">

**Author:** ![scott.nemes](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/scott.nemes/32/5_2.png) [@scott.nemes](https://forums.percona.com/u/scott.nemes)\
**Post date:** [December 19, 2014, 9:11am UTC](https://forums.percona.com/t/why-pt-kill-hangs-in-connecting-to-mysql/3957/4 "2014-12-19T09:11:43Z")

</div>

Hi leafonsword;

By default pt-kill is only killing running queries, where the “command” (current state) is “query”. It appears you are attempting to kill stale connections where the command would be “sleep” (that may or may not have some junk left over like you mentioned). For that, I would look into the --match-command option.

However if you are going to kill queries that are just sleeping, I would recommend waiting longer than the six seconds you specified previously otherwise you’ll probably be creating more churn than it’s worth as it takes time and system resources to keep opening and closing the connections constantly and may result in unexpected results in your application.

[url][pt-kill — Percona Toolkit Documentation](http://www.percona.com/doc/percona-toolkit/2.2/pt-kill.html#cmdoption-pt-kill--match-command%5B/url%5D)

-Scott

---

<div class="post-metadata">

**Author:** ![leafonsword](https://avatars.discourse-cdn.com/v4/letter/l/85f322/32.png) [@leafonsword](https://forums.percona.com/u/leafonsword)\
**Post date:** [December 20, 2014, 8:50pm UTC](https://forums.percona.com/t/why-pt-kill-hangs-in-connecting-to-mysql/3957/5 "2014-12-20T20:50:17Z")

</div>

> [@scott.nemes;28771](#):
>
> Hi leafonsword;
> 
> By default pt-kill is only killing running queries, where the “command” (current state) is “query”. It appears you are attempting to kill stale connections where the command would be “sleep” (that may or may not have some junk left over like you mentioned). For that, I would look into the --match-command option.
> 
> However if you are going to kill queries that are just sleeping, I would recommend waiting longer than the six seconds you specified previously otherwise you’ll probably be creating more churn than it’s worth as it takes time and system resources to keep opening and closing the connections constantly and may result in unexpected results in your application.
> 
> [http://www.percona.com/doc/percona-toolkit/2.2/pt-kill.html#cmdoption-pt-kill–match-command](http://www.percona.com/doc/percona-toolkit/2.2/pt-kill.html#cmdoption-pt-kill--match-command)
> 
> -Scott

Thx for your explaining！
