如何从命令行清除未执行的 MySQL 查询?

发布于 2024-12-25 22:14:28 字数 384 浏览 0 评论 0原文

假设您正在向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

好久不见√ 2025-01-01 22:14:28

输入\c

当您启动 MySQL 时,您可能会看到以下消息:

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

它所指的“缓冲区”是命令/查询缓冲区。

Type \c.

When you start up MySQL, you'll likely see this message:

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

The "buffer" that it's referring to is the command/query buffer.

只是我以为 2025-01-01 22:14:28

首先输入 Ctrl+a,然后输入 Ctrl+k

First type Ctrl+a, then Ctrl+k.

旧梦荧光笔 2025-01-01 22:14:28

使用以下快捷键之一删除当前行:

  • 键入 Ctrl + u 删除从光标到行开头的所有内容
  • 键入 Ctrl + k 删除从光标到行尾的所有内容

否则,如前所述,在当前行末尾键入 \cclear 命令),然后按 Enter

Use one of the following shortcuts to delete the current line:

  • Type Ctrl + u to delete everything from the cursor back to the line start
  • Type Ctrl + k to delete everything from the cursor to the end of the line

Otherwise as already indicated type \c at the end of the current line (a shortcut for the clear command) and then press Enter.

我不吻晚风 2025-01-01 22:14:28

在 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.

末が日狂欢 2025-01-01 22:14:28

如果它是一个长命令,我通常将箭头指向命令的开头并添加乱码,因此它不会执行,但我可以向上箭头并获得访问权限,而无需重新输入它。否则,如果您不想执行它,只需点击向上箭头,它就会滚动您的命令历史记录。找到一个简短的命令,退格,然后输入您想要的任何内容。

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.

萌化 2025-01-01 22:14:28

取决于您的 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

悲凉≈ 2025-01-01 22:14:28

如果您希望在 Transact-SQL 中找到相同的答案,请输入 RESET

If you came here hoping to find the same answer in Transact-SQL, type RESET

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文