MySQLでやりたいことから調べられるリファレンス

MySQL 逆引きリファレンス

プロセスを強制的に停止する(mysqladmin)

スポンサードリンク

mysqladmin コマンドを使用して MySQL で実行中のプロセスを強制的に停止することができます。

使用例
mysqladmin kill プロセスID

パスワードが設定されている場合は、オプションでユーザー名を指定し、パスワード送信オプションを指定します。

使用例
mysqladmin kill プロセスID -u root -p

プロセスID の一覧は mysqladmin processlist で調べることができます。
これによりプロセスID を指定してプロセスを強制的に終了させることができます。

使用例
mysqladmin kill プロセスID1,プロセスID2,プロセスID3 -u root -p
(以下の例では、Info 列を省略しています。)
D:\MySQL\bin>mysqladmin processlist -u root -p
Enter password: ***********
+----+------+----------------+------+---------+------+------------------+
| Id | User | Host           | db   | Command | Time | State            |
+----+------+----------------+------+---------+------+------------------+
| 5  | root | localhost:2054 | test | Connect | 623  | Reading from net |
| 8  | root | localhost:2084 | test | Connect | 430  | Reading from net |
| 10 | root | localhost:2086 | test | Sleep   | 267  |                  |
| 12 | root | localhost:2128 | test | Connect | 256  | Reading from net |
| 13 | root | localhost:2129 | test | Connect | 248  | Reading from net |
| 16 | root | localhost:2134 |      | Query   | 0    |                  |
+----+------+----------------+------+---------+------+------------------+

D:\MySQL\bin>mysqladmin kill 12 -u root -p
Enter password: ***********

D:\MySQL\bin>mysqladmin processlist -u root -p
Enter password: ***********
+----+------+----------------+------+---------+------+------------------+
| Id | User | Host           | db   | Command | Time | State            |
+----+------+----------------+------+---------+------+------------------+
| 5  | root | localhost:2054 | test | Connect | 648  | Reading from net |
| 8  | root | localhost:2084 | test | Connect | 455  | Reading from net |
| 10 | root | localhost:2086 | test | Sleep   | 292  |                  |
| 13 | root | localhost:2129 | test | Connect | 273  | Reading from net |
| 18 | root | localhost:2136 |      | Query   | 0    |                  |
+----+------+----------------+------+---------+------+------------------+

強制的に終了するプロセスを複数指定することも可能です。
この場合、プロセスID をカンマ区切りで指定します。

D:\MySQL\bin>mysqladmin processlist -u root -p
Enter password: ***********
+----+------+----------------+------+---------+------+------------------+
| Id | User | Host           | db   | Command | Time | State            |
+----+------+----------------+------+---------+------+------------------+
| 39 | root | localhost:2220 | test | Connect | 41   | Reading from net |
| 40 | root | localhost:2221 | test | Connect | 30   | Reading from net |
| 41 | root | localhost:2222 | test | Connect | 24   | Reading from net |
| 42 | root | localhost:2223 | test | Connect | 17   | Reading from net |
| 43 | root | localhost:2224 | test | Connect | 10   | Reading from net |
| 44 | root | localhost:2225 |      | Query   | 0    |                  |
+----+------+----------------+------+---------+------+------------------+

D:\MySQL\bin>mysqladmin kill 39,40,41,42 -u root -p
Enter password: ***********

D:\MySQL\bin>mysqladmin processlist -u root -p
Enter password: ***********
+----+------+----------------+------+---------+------+------------------+
| Id | User | Host           | db   | Command | Time | State            |
+----+------+----------------+------+---------+------+------------------+
| 43 | root | localhost:2224 | test | Connect | 30   | Reading from net |
| 46 | root | localhost:2227 |      | Query   | 0    |                  |
+----+------+----------------+------+---------+------+------------------+

複数ID を指定する際、カンマの後ろに半角スペースを含めてしまうとコマンドは正しく実行されないので注意が必要です。

D:\MySQL\bin>mysqladmin processlist -u root -p
Enter password: ***********
+----+------+----------------+------+---------+------+------------------+
| Id | User | Host           | db   | Command | Time | State            |
+----+------+----------------+------+---------+------+------------------+
| 43 | root | localhost:2224 | test | Connect | 228  | Reading from net |
| 47 | root | localhost:2228 | test | Connect | 31   | Reading from net |
| 48 | root | localhost:2229 | test | Connect | 25   | Reading from net |
| 49 | root | localhost:2230 | test | Connect | 18   | Reading from net |
| 50 | root | localhost:2231 | test | Connect | 10   | Reading from net |
| 51 | root | localhost:2232 |      | Query   | 0    |                  |
+----+------+----------------+------+---------+------+------------------+

D:\MySQL\bin>mysqladmin kill 43, 47, 48, 49, 50 -u root -p
Enter password: ***********
mysqladmin: kill failed on 0; error: 'Unknown thread id: 0'

D:\MySQL\bin>mysqladmin processlist -u root -p
Enter password: ***********
+----+------+----------------+------+---------+------+------------------+
| Id | User | Host           | db   | Command | Time | State            |
+----+------+----------------+------+---------+------+------------------+
| 47 | root | localhost:2228 | test | Connect | 54   | Reading from net |
| 48 | root | localhost:2229 | test | Connect | 48   | Reading from net |
| 49 | root | localhost:2230 | test | Connect | 41   | Reading from net |
| 50 | root | localhost:2231 | test | Connect | 33   | Reading from net |
| 53 | root | localhost:2234 |      | Query   | 0    |                  |
+----+------+----------------+------+---------+------+------------------+
スポンサードリンク

mysqladminコマンド関連

システム関連

その他のカテゴリー一覧