如何中断一个长查询在mysql命令行工具,而不退出mysql? [英] How do I Interupt a long query in the mysql command line tool without quitting mysql?

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

问题描述

在调试SQL语句时,如果我在使用mysql命令行意外执行一个查询,输出很多结果(即使查询本身在合理的时间内执行),我知道的唯一的方法是停止无尽的流输出是CTRL-C。



不幸的是,这让我回到shell,强迫我登录并再次选择数据库。



为了避免这种情况,我已经开始使用 - sigint-ignore 选项运行mysql,因此CTRL-C被忽略了。



现在我想要一种方法来中断这些长查询的输出。



有没有键盘快捷键可以做到这一点?

解决方案

您可以使用 - pager 将您的输出传递到诸如的寻呼机,输出。



还有 - safe -updates -U 切换aka - i-am-a-dummy 保护您免于无礼的更新 s和删除 s,并且自动限制选择为1000(可以使用select_limit修改) p>

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

  [mysql] 
pager
安全更新


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天全站免登陆