To invoke a MySQL program from the command line (that is, from your shell or command prompt), enter the program name followed by any options or other arguments needed to instruct the program what you want it to do. 要从命令行(即,从shell或命令提示符)调用MySQL程序,请输入程序名,后跟指示程序所需操作的任何选项或其他参数。The following commands show some sample program invocations. 以下命令显示了一些示例程序调用。shell>
represents the prompt for your command interpreter; it is not part of what you type. shell>
表示命令解释器的提示;它不是您键入内容的一部分。The particular prompt you see depends on your command interpreter. 您看到的特定提示取决于您的命令解释器。Typical prompts are 对于sh、ksh或bash,典型提示为$
for sh, ksh, or bash, %
for csh or tcsh, and C:\>
for the Windows command.com or cmd.exe command interpreters.$
,对于csh或tcsh,提示为%
;而C:\>
用于Windows command.com或cmd.exe命令解释器。
shell>mysql --user=root test
shell>mysqladmin extended-status variables
shell>mysqlshow --help
shell>mysqldump -u root personnel
Arguments that begin with a single or double dash (以单破折号或双破折号(-
, --
) specify program options. -
、--
)开头的参数指定程序选项。Options typically indicate the type of connection a program should make to the server or affect its operational mode. Option syntax is described in Section 4.2.2, “Specifying Program Options”.选项通常指示程序应与服务器建立的连接类型或影响其操作模式。选项语法见第4.2.2节,“指定程序选项”。
Nonoption arguments (arguments with no leading dash) provide additional information to the program. 非选项参数(不带前导破折号的参数)为程序提供附加信息。For example, the mysql program interprets the first nonoption argument as a database name, so the command 例如,mysql程序将第一个nonoption参数解释为数据库名称,因此命令mysql --user=root test
indicates that you want to use the test
database.mysql --user=root test
指示您要使用测试数据库。
Later sections that describe individual programs indicate which options a program supports and describe the meaning of any additional nonoption arguments.后面描述单个程序的部分指出程序支持哪些选项,并描述任何附加非选项参数的含义。
Some options are common to a number of programs. 一些选项是许多程序所共有的。The most frequently used of these are the 其中最常用的是指定连接参数的--host
(or -h
), --user
(or -u
), and --password
(or -p
) options that specify connection parameters. --host
(或-h
)、--user
(或-u
)和--password
(或-p
)选项。They indicate the host where the MySQL server is running, and the user name and password of your MySQL account. 它们表示MySQL服务器运行的主机,以及MySQL帐户的用户名和密码。All MySQL client programs understand these options; they enable you to specify which server to connect to and the account to use on that server. 所有MySQL客户端程序都理解这些选项;它们使您能够指定要连接到的服务器以及要在该服务器上使用的帐户。Other connection options are 其他连接选项包括--port
(or -P
) to specify a TCP/IP port number and --socket
(or -S
) to specify a Unix socket file on Unix (or named-pipe name on Windows). --port
(或-p
)以指定TCP/IP端口号,以及--socket
(或-s
)以指定Unix上的Unix套接字文件(或Windows上的命名管道名称)。For more information on options that specify connection options, see Section 4.2.4, “Connecting to the MySQL Server Using Command Options”.有关指定连接选项的选项的更多信息,请参阅第4.2.4节,“使用命令选项连接到MySQL服务器”。
You may find it necessary to invoke MySQL programs using the path name to the 您可能会发现有必要使用安装MySQL程序的bin
directory in which they are installed. bin
目录的路径名来调用MySQL程序。This is likely to be the case if you get a “program not found” error whenever you attempt to run a MySQL program from any directory other than the 当您试图从bin
directory. bin
目录以外的任何目录运行MySQL程序时,如果出现“未找到程序”错误,则可能会出现这种情况。To make it more convenient to use MySQL, you can add the path name of the 为了更方便地使用MySQL,您可以将bin
directory to your PATH
environment variable setting. bin
目录的路径名添加到PATH
环境变量设置中。That enables you to run a program by typing only its name, not its entire path name. 这使您能够通过只键入程序名而不是整个路径名来运行程序。For example, if mysql is installed in 例如,如果mysql安装在/usr/local/mysql/bin
, you can run the program by invoking it as mysql, and it is not necessary to invoke it as /usr/local/mysql/bin/mysql./usr/local/mysql/bin
中,则可以通过调用mysql来运行程序,而不必调用/usr/local/mysql/bin/mysql
。
Consult the documentation for your command interpreter for instructions on setting your 有关设置PATH
variable. PATH
变量的说明,请参阅命令解释器的文档。The syntax for setting environment variables is interpreter-specific. 设置环境变量的语法是特定于解释器的。(Some information is given in Section 4.2.9, “Setting Environment Variables”.) (第4.2.9节,“设置环境变量”中给出了一些信息。)After modifying your 修改PATH
setting, open a new console window on Windows or log in again on Unix so that the setting goes into effect.PATH
设置后,请在Windows上打开一个新的控制台窗口,或在Unix上再次登录,以便该设置生效。