How do I Interrupt a long query in the mysql command line tool without quitting mysql?

前端 未结 5 991
囚心锁ツ
囚心锁ツ 2020-12-29 22:12

While debugging SQL statements, if I accidentally execute a query in using the mysql command line that outputs at lot of results (even if the query itself executes in reaso

相关标签:
5条回答
  • 2020-12-29 22:31

    Use mysql --sigint-ignore

    and to clear a line, use control+U

    0 讨论(0)
  • 2020-12-29 22:32

    You can use --pager to have your output passed to a pager such as less which will give you control over the output. Not just killing it, but also paging, searching and even storing the output better than your terminal window gives you.

    There's also the --safe-updates or -U switch aka --i-am-a-dummy which protects you from clauseless updates and deletes and also auto limits selects to 1000 (modifyable with select_limit).

    All of this can be set by default in ~/.my.cnf.

    [mysql]
    pager
    safe-updates
    
    0 讨论(0)
  • 2020-12-29 22:35

    Not a keyboard shortcut.

    The only choice is to open another session, use SHOW PROCESSLIST and then KILL QUERY the one you want to terminate.

    You can also use the mysqladmin command-line tool to issue these commands.

    Either way, it requires you to login. So it's not much of an advantage over just hitting Ctrl-C.

    0 讨论(0)
  • 2020-12-29 22:35

    From the current mysql docs:

    As of MySQL 5.1.10, typing Control-C causes mysql to attempt to kill the current statement. If this cannot be done, or Control-C is typed again before the statement is killed, mysql exits. Previously, Control-C caused mysql to exit in all cases.

    Since I was using version 5.0.67 seems that updating mysql would be the best fix. However I have accepted Schwern's answer because it was quick to implement and works like a dream.

    0 讨论(0)
  • 2020-12-29 22:38

    Bit late, but maybe my answer will help someone.

    A way to kill a concrete mysql query through the command line is:

    1. Identify the process id of that query by the command: mysqladmin processlist
    2. Assuming that the Id is the 5736748, to kill the query you have to type: mysqladmin kill 5736748
    0 讨论(0)
提交回复
热议问题