如何在不退出mysql的情况下中断mysql命令行工具中的长查询? [英] How do I Interrupt a long query in the mysql command line tool without quitting mysql?

查看:793
本文介绍了如何在不退出mysql的情况下中断mysql命令行工具中的长查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试SQL语句时,如果我不小心使用输出大量结果的mysql命令行执行了查询(即使查询本身在合理的时间执行),我知道的唯一方法就是停止无休止的输出为CTRL-C.

不幸的是,这使我回到了外壳中,迫使我再次登录并选择数据库.

为避免这种情况,我开始使用-sigint-ignore 选项运行mysql,以便忽略CTRL-C.

现在,我想一种方法来中断那些长查询的输出.

是否存在可以执行此操作的键盘快捷键?

解决方案

您可以使用--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

这篇关于如何在不退出mysql的情况下中断mysql命令行工具中的长查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆