中止错误的多行SQL语句执行

一、背景

经常会出现在命令行编写多行SQL过程中,发现语法有问题。
此时,需要中止错误的SQL语句,取消SQL执行。

二、实例

编写多行SQL,中途发现语法错误,可以通过\c来中止。
如若SQL内容较多,可以通过\p打印出已经编写的SQL语句。

1
2
3
4
5
6
7
mysql> select 123
-> \p
--------------
select 123
--------------

-> \c

三、扩展知识

更多mysql命令如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

四、参考文档

文章目录
  1. 一、背景
  2. 二、实例
  3. 三、扩展知识
  4. 四、参考文档
|