且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不退出mysql的情况下中断mysql命令行工具中的长查询?

更新时间:2022-10-25 13:28:59

您可以使用--pager将您的输出传递到诸如less的寻呼机,这将使您可以控制输出.不仅可以杀死它,而且分页,搜索甚至存储输出都比终端窗口更好.

还有一个--safe-updates-U开关(又名--i-am-a-dummy),可以保护您免受无子句的updatedelete的侵害,还可以将自动限制选择范围限制为1000(可通过select_limit修改).

所有这些都可以在~/.my.cnf中默认设置.

[mysql]
pager
safe-updates

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 reasonable time), the only way I know of to stop the endless stream of output is CTRL-C.

Unfortunately this puts me back in the shell, forcing me to login and select the database again.

To avoid this I've started running mysql with the --sigint-ignore option so that CTRL-C is ignored.

Now I'd like a way to interrupt the output of those long queries.

Is there a keyboard shortcut that will do this?

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