4.5.1.2 mysql Client Commandsmysql客户端命令

mysql sends each SQL statement that you issue to the server to be executed. mysql将您发出的每个SQL语句发送到服务器以供执行。There is also a set of commands that mysql itself interprets. 还有一组mysql自己解释的命令。For a list of these commands, type help or \h at the mysql> prompt:要查看这些命令的列表,请在mysql>提示符下键入help\h

mysql> help

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.
resetconnection(\x) Clean session context.
query_attributes(\) Sets string parameters (name1 value1 name2 value2 ...)
for the next query to pick up.

For server side help, type 'help contents'

If mysql is invoked with the --binary-mode option, all mysql commands are disabled except charset and delimiter in noninteractive mode (for input piped to mysql or loaded using the source command).如果使用--binary-mode选项调用mysql,则除非交互模式下的charsetdelimiter(用于通过管道传输到mysql或使用源命令加载的输入)外,所有mysql命令都将被禁用。

Each command has both a long and short form. The long form is not case-sensitive; the short form is. The long form can be followed by an optional semicolon terminator, but the short form should not.每个命令都有长形式和短形式。长形式不区分大小写;短形式是。长形式后面可以跟一个可选的分号终止符,但短形式不应该跟在后面。

The use of short-form commands within multiple-line /* ... */ comments is not supported. 不支持在多行/* ... */注释中使用短格式命令。Short-form commands do work within single-line /*! ... */ version comments, as do /*+ ... */ optimizer-hint comments, which are stored in object definitions. 短格式命令在单行/*! ... */版本注释内有效,以及/*+ ... */优化器提示注释,存储在对象定义中。If there is a concern that optimizer-hint comments may be stored in object definitions so that dump files when reloaded with mysql would result in execution of such commands, either invoke mysql with the --binary-mode option or use a reload client other than mysql.如果担心优化器提示注释可能存储在对象定义中,因此用mysql重新加载转储文件时会导致执行此类命令,请使用--binary-mode选项调用mysql或使用mysql以外的重新加载客户端。

Here are a few tips about the pager command:以下是关于pager命令的一些提示:

You can also combine the tee and pager functions. 您还可以组合teepager功能。Have a tee file enabled and pager set to less, and you are able to browse the results using the less program and still have everything appended into a file the same time. 启用tee文件并将pager设置为更少,您就可以使用less程序浏览结果,并且仍然可以同时将所有内容附加到文件中。The difference between the Unix tee used with the pager command and the mysql built-in tee command is that the built-in tee works even if you do not have the Unix tee available. pager命令一起使用的Unix tee和mysql内置tee命令之间的区别在于,即使您没有可用的Unix tee,内置tee也能工作。The built-in tee also logs everything that is printed on the screen, whereas the Unix tee used with pager does not log quite that much. 内置的tee也会记录屏幕上打印的所有内容,而与pager一起使用的Unix tee不会记录那么多。Additionally, tee file logging can be turned on and off interactively from within mysql. 此外,可以从mysql中交互式地打开和关闭tee文件日志记录。This is useful when you want to log some queries to a file, but not others.当您想将某些查询记录到文件中,而不将其他查询记录到某个文件中时,这很有用。

The prompt command reconfigures the default mysql> prompt. The string for defining the prompt can contain the following special sequences.prompt命令重新配置默认的mysql>提示符。用于定义提示的字符串可以包含以下特殊序列。

Option选项Description描述
\CThe current connection identifier当前连接标识符
\cA counter that increments for each statement you issue为您发出的每条语句递增的计数器
\DThe full current date当前完整日期
\dThe default database默认数据库
\hThe server host服务器主机
\lThe current delimiter当前分隔符
\mMinutes of the current time当前时间的分钟数
\nA newline character换行符
\OThe current month in three-letter format (Jan, Feb, …)以三个字母格式表示的当前月份(Jan、Feb、……)
\oThe current month in numeric format数字格式的当前月份
\Pam/pm
\pThe current TCP/IP port or socket file当前TCP/IP端口或套接字文件
\RThe current time, in 24-hour military time (0–23)当前时间,以24小时军事时间(0-23)表示
\rThe current time, standard 12-hour time (1–12)当前时间,标准12小时时间(1-12)
\SSemicolon分号
\sSeconds of the current time当前时间的秒数
\tA tab character制表符字符
\U

Your full user_name@host_name account name您的完整user_name@host_name账户名称

\uYour user name您的用户名
\vThe server version服务器版本
\wThe current day of the week in three-letter format (Mon, Tue, …)以三个字母格式表示一周中的当前日期(星期一、星期二、……)
\YThe current year, four digits当前年份,四位数
\yThe current year, two digits当前年份,两位数
\_A space一个空格
A space (a space follows the backslash)一个空格(反斜杠后面有空格)
\'Single quote单引号
\"Double quote双引号
\\A literal \ backslash character一个文字\反斜杠字符
\x

x, for any x not listed abovex、 对于上面未列出的任何“x

You can set the prompt in several ways:您可以通过多种方式设置提示: