ãã¾ãã«ãå¦çã«æéãããããããªSQLãå®è¡ãã¦ãã¾ããMySQLãããã¨ãããã¨ãè¨ããªããªã£ã¦ãã¾ããããªç¶æ³ãããããã¾ããããã£ã¦ããããã¾ããããªç¶æ³ãã£ã¦ã¯ãªããªããã§ãããæãã¾ããã¾ãããããªæãåé¡ã¨ãªã£ã¦ããã¯ã¨ãªã®å¦çãæ¢ãããããã§ãã
ç¹å®ã®ã¯ã¨ãªãæ¢ããæ¹æ³
MySQLã§å®è¡ä¸ã®ã¯ã¨ãªä¸è¦§ãè¦ã¦ãSQLãå¼·å¶çµäºããæ¹æ³
ãã¡ããè¦ã¦ããããã°ããæ¹ã¯åããã¾ããåç´ã«MySQLã«å ¥ã£ã¦ãshow processlist;ã§åé¡ã®ããã¯ã¨ãªãçºè¦ããããã»ã¹IDã kill ããã ããã¨ã¦ãç°¡åã
è¤æ°ã®ã¯ã¨ãªãä¸æ¬ã§æ¢ããæ¹æ³
ä»åã¯åé¡ã®ããã¯ã¨ãªã100åãã£ããã©ãããâ¦ï¼çãªã®ã解決ããã¨ã³ããªã¼ã§ããã¾ããåé¡ããã¯ã¨ãª100åããç¶æ³ã¯ãã¢ããªçã«åé¡ããããããï¼ã£ã¦ããã¬ãã«ã§ããã
1åãã¤ããã»ã¹IDãã³ãããã¦â¦ãªãã¦ãã£ã¦ãããªãã§ããããã¾ã¨ãã¦killãã¡ãããããå®ã¯ãshow full processlistã¯ä»¥ä¸ã®SQLã¨åãã
SELECT * FROM information_schema.PROCESSLIST;
ã¨ãããã¨ã¯ãæ®éã«whereå¥ãªã©ã§æ¡ä»¶ãæå®ã§ããã
å¦çæéã«60ç§ä»¥ä¸ããã£ã¦ããã®ã表示
SELECT * FROM information_schema.PROCESSLIST WHERE TIME > 59;
ã¨ãããã¨ã¯ãIDã1è¡ã«ã¾ã¨ããããã
SELECT GROUP_CONCAT(ID) FROM information_schema.PROCESSLIST WHERE TIME > 59;
+------------------+
| group_concat(ID) |
+------------------+
| 1,2,3,4,5 |
+------------------+
GROUP_CONCAT()é¢æ°ã使ããã¨ã§ãè¤æ°ã¬ã³ã¼ããã«ã³ãåºåãã®1è¡ã«ã¾ã¨ãããã¾ããããã¤ã¯ãããã
è¤æ°ã®ããã»ã¹IDãkillãã
ãã¨ã¯ãããã¤ãkillããã°è¯ãã ããªãã§ãããMySQLå ã®killã³ãã³ãã§ã¯è¤æ°IDãåãä»ãã¦ããã¾ããã
kill 1,2,3; # ããã¯é§ç®
ã¨ããããã§ããã£ããMySQLããæãã¦ãæ®éã®ã³ã³ã½ã¼ã«ããmysqladminã³ãã³ãã使ç¨ãã¾ããmysqladminã®killã¯ã«ã³ãåºåãã§è¤æ°ã®IDãåãä»ãã¦ããã¾ããå¿ãåºãã
$ mysqladmin kill 1,2,3 -h localhost -u hoge
æ±ç©ã¯æ¶æ¯ã ï½ã£ï¼ï¼ã°ãã®ããªã§æ®ºãã¦ããã¾ããããã§ãã£ã¨ãã®å®å¯§ã訪ãã¾ãããããããã®åå ã¨ãªã£ã¦ããSQLãã¢ããªã±ã¼ã·ã§ã³ãä¿®æ£ããªãã¨é§ç®ã§ãããã¯ãã