如何从命令行清除未执行的 MySQL 查询?
假设您正在向 MySQL 数据库输入命令行查询,并且需要取消并重新开始。在 bash shell 中,您只需键入 ctrl-c 即可获得新的提示符。在 MySQL 中,ctrl-c 将退出客户端并返回到 shell。
例如,我输入了一个又长又复杂的 SELECT 语句,但尚未按回车键。我意识到我不想发送命令,但我想在屏幕上显示该命令,以便我可以将其用作参考。我想在不退出 MySQL 的情况下摆脱困境。有什么想法吗?
关键点: 命令尚未执行。
Suppose you're typing a command line query into a MySQL database and you need to cancel out and start over. From a bash shell you could just type ctrl-c and get a new prompt. In MySQL, ctrl-c would exit the client and return you to the shell.
For example, I have a long, complex SELECT statement typed in but I haven't yet hit return. I realize that I don't want to send the command but I want to have the command on-screen so I can use it as a reference. I'd like to bail out without quitting MySQL. Any ideas?
Key point: the command hasn't yet been executed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
输入
\c
。当您启动 MySQL 时,您可能会看到以下消息:
它所指的“缓冲区”是命令/查询缓冲区。
Type
\c
.When you start up MySQL, you'll likely see this message:
The "buffer" that it's referring to is the command/query buffer.
首先输入 Ctrl+a,然后输入 Ctrl+k。
First type Ctrl+a, then Ctrl+k.
使用以下快捷键之一删除当前行:
否则,如前所述,在当前行末尾键入 \c (
clear
命令),然后按 Enter。Use one of the following shortcuts to delete the current line:
Otherwise as already indicated type \c at the end of the current line (a shortcut for the
clear
command) and then press Enter.在 mysql 5.7 中,这个问题已经得到解决。您现在可以执行
ctrl-c
退出 SQL 命令行。In mysql 5.7, this has been resolved. You can now do
ctrl-c
to exit the SQL command line.如果它是一个长命令,我通常将箭头指向命令的开头并添加乱码,因此它不会执行,但我可以向上箭头并获得访问权限,而无需重新输入它。否则,如果您不想执行它,只需点击向上箭头,它就会滚动您的命令历史记录。找到一个简短的命令,退格,然后输入您想要的任何内容。
If it's a long command I usually arrow to the beginning of the command and add gibberish, so it won't execute, but I can up-arrow and gain access without having to re-type it. Otherwise if you want to not execute it, just hit the up-arrow and it should scroll you through your command history. Find a short command, backspace, then type whatever you want.
取决于您的 shell 的键绑定。你可以按 home 或任何你用来返回开始的键序列,在你的查询前面加上 X 或任何使它在语法上无效的东西,按回车键就可以了
Depends on your shell's key bindings. You could press home or what ever key sequence you use to get back to the start, prefix your query with X or what ever to make it syntactically invalid, hit enter and you're good
如果您希望在 Transact-SQL 中找到相同的答案,请输入
RESET
If you came here hoping to find the same answer in Transact-SQL, type
RESET