How can I stop a running MySQL query?

后端 未结 7 1377
梦如初夏
梦如初夏 2020-12-04 05:05

I connect to mysql from my Linux shell. Every now and then I run a SELECT query that is too big. It prints and prints and I already know this is no

相关标签:
7条回答
  • 2020-12-04 05:44

    Just to add

    KILL QUERY **Id** where Id is connection id from show processlist

    is more preferable if you are do not want to kill the connection usually when running from some application.

    For more details you can read mysql doc here

    0 讨论(0)
  • 2020-12-04 05:54

    If you have mysqladmin available, you may get the list of queries with:

    > mysqladmin -uUSERNAME -pPASSWORD pr
    
    +-----+------+-----------------+--------+---------+------+--------------+------------------+
    | Id  | User | Host            | db     | Command | Time | State        | Info             |
    +-----+------+-----------------+--------+---------+------+--------------+------------------+
    | 137 | beet | localhost:53535 | people | Query   | 292  | Sending data | DELETE FROM      |
    | 145 | root | localhost:55745 |        | Query   | 0    |              | show processlist |
    +-----+------+-----------------+--------+---------+------+--------------+------------------+
    

    Then you may stop the mysql process that is hosting the long running query:

    > mysqladmin -uUSERNAME -pPASSWORD kill 137
    
    0 讨论(0)
  • 2020-12-04 06:00

    You need to run following command to kill the process.

    > show processlist;  
    > kill query processId;
    

    Query parameter specifies that we need to kill query command process.

    The syntax for kill process as follows

    KILL [CONNECTION | QUERY] processlist_id

    Please refer this link for more information.

    0 讨论(0)
  • 2020-12-04 06:01
    mysql>show processlist;
    
    mysql> kill "number from first col";
    
    0 讨论(0)
  • 2020-12-04 06:02

    Use mysqladmin to kill the runaway query:

    Run the following commands:

    mysqladmin -uusername -ppassword pr
    

    Then note down the process id.

    mysqladmin -uusername -ppassword kill pid
    

    The runaway query should no longer be consuming resources.

    0 讨论(0)
  • 2020-12-04 06:04

    Connect to mysql

    mysql -uusername -p  -hhostname
    

    show full processlist:

    mysql> show full processlist;
    +---------+--------+-------------------+---------+---------+------+-------+------------------+
    | Id      | User   | Host              | db      | Command | Time | State | Info             |
    +---------+--------+-------------------+---------+---------+------+-------+------------------+
    | 9255451 | logreg | dmin001.ops:37651 | logdata | Query   |    0 | NULL  | show processlist |
    +---------+--------+-------------------+---------+---------+------+-------+------------------+
    

    Kill the specific query. Here id=9255451

    mysql> kill 9255451;
    

    If you get permission denied, try this SQL:

    CALL mysql.rds_kill(9255451)
    
    0 讨论(0)
提交回复
热议问题