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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8811464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:19:01  来源:igfitidea点击:

How do you clear an unexecuted MySQL query from the command line?

mysqlcommand-line

提问by Logan

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.

假设您在 MySQL 数据库中键入命令行查询,并且您需要取消并重新开始。在 bash shell 中,您只需键入 ctrl-c 并获得新提示。在 MySQL 中,ctrl-c 将退出客户端并将您返回到 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?

例如,我输入了一个又长又复杂的 SELECT 语句,但我还没有按回车键。我意识到我不想发送命令,但我想在屏幕上显示命令,以便我可以将其用作参考。我想在不退出 MySQL 的情况下退出。有任何想法吗?

Key point: the command hasn't yet been executed.

关键点:命令尚未执行

回答by ruakh

Type \c.

键入\c

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

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

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

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

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

回答by untill

First type Ctrl+a, then Ctrl+k.

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

回答by bladerz

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

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

  • Type Ctrl+ uto delete everything from the cursor back to the line start
  • Type Ctrl+ kto delete everything from the cursor to the end of the line
  • 键入Ctrl+u删除从光标回到行开始的所有内容
  • 键入Ctrl+k删除从光标到行尾的所有内容

Otherwise as already indicated type \cat the end of the current line (a shortcut for the clearcommand) and then press Enter.

否则\c,在当前行的末尾输入已指示的类型(clear命令的快捷方式),然后按Enter

回答by Helzgate

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

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

回答by dkniffin

In mysql 5.7, this has been resolved. You can now do ctrl-cto exit the SQL command line.

在 mysql 5.7 中,这个问题已经解决。您现在ctrl-c可以退出 SQL 命令行。

回答by Mike Purcell

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.

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

回答by atxdba

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

取决于你的 shell 的键绑定。您可以按 home 或您使用的任何键序列返回开始,在您的查询前加上 X 或其他任何使其在语法上无效的内容,按 Enter 即可