8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

6.2.1 调用 MySQL 程序6.2.1 Invoking MySQL Programs

要从命令行调用 MySQL 程序(也就是从你的 shell 或命令提示符),输入程序名称,然后附加任何选项或其他参数,以指示程序你希望它执行的操作。以下命令显示了一些示例程序调用。$> 表示命令解释器的提示符;它不是你要输入的内容。你看到的具体提示符取决于你的命令解释器。典型的提示符有:对于 sh、ksh 或 bash 为 $,对于 csh 或 tcsh 为 %,对于 Windows 的 command.com 或 cmd.exe 命令解释器为 C:\>。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. The following commands show some sample program invocations. $> represents the prompt for your command interpreter; it is not part of what you type. The particular prompt you see depends on your command interpreter. Typical prompts are $ for sh, ksh, or bash, % for csh or tcsh, and C:\> for the Windows command.com or cmd.exe command interpreters.

$> mysql --user=root test
$> mysqladmin extended-status variables
$> mysqlshow --help
$> mysqldump -u root personnel

以单个或双破折号 (-,--) 开头的参数用于指定程序选项。选项通常指示程序应如何连接到服务器或影响其操作模式。选项的语法在 第 6.2.2 节,“指定程序选项” 中有描述。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 6.2.2, “Specifying Program Options”.

非选项参数(没有前导破折号的参数)为程序提供额外信息。例如,mysql 程序将第一个非选项参数解释为数据库名,因此命令 mysql --user=root test 表示您想使用 test 数据库。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 --user=root test indicates that you want to use the test database.

后续描述各个程序的章节会说明程序支持哪些选项,并描述任何额外非选项参数的含义。Later sections that describe individual programs indicate which options a program supports and describe the meaning of any additional nonoption arguments.

有些选项在多个程序中是通用的。其中最常用的是--host(或-h)、--user(或-u)和--password(或-p)选项,用于指定连接参数。它们用于指明 MySQL 服务器运行的主机,以及您 MySQL 账户的用户名和密码。所有 MySQL 客户端程序都支持这些选项;它们允许您指定要连接的服务器以及在该服务器上使用的账户。其他连接选项包括--port(或-P)用于指定 TCP/IP 端口号,以及--socket(或-S)用于在 Unix 上指定 Unix 套接字文件(或在 Windows 上指定命名管道名)。有关指定连接选项的更多信息,请参阅第 6.2.4 节,“使用命令选项连接到 MySQL 服务器”。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. They indicate the host where the MySQL server is running, and the user name and password of your MySQL account. 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. 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). For more information on options that specify connection options, see Section 6.2.4, “Connecting to the MySQL Server Using Command Options”.

您可能需要使用 MySQL 程序所在的 bin 目录的路径来调用这些程序。如果每次尝试在 bin 目录以外的任何目录运行 MySQL 程序时都出现 “找不到程序” 错误,那么这种情况很可能会发生。为了更方便地使用 MySQL,您可以将 bin 目录的路径添加到您的 PATH 环境变量设置中。这样,您只需输入程序名称即可运行,而无需输入完整路径。例如,如果 mysql 安装在 /usr/local/mysql/bin,您可以通过调用 mysql 来运行该程序,而不必调用 /usr/local/mysql/bin/mysql。You may find it necessary to invoke MySQL programs using the path name to the bin directory in which they are installed. 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. To make it more convenient to use MySQL, you can add the path name of the bin directory to your PATH environment variable setting. That enables you to run a program by typing only its name, not its entire path name. For example, if mysql is installed in /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.

请查阅您的命令解释器的文档,以获取有关设置PATH变量的说明。设置环境变量的语法因解释器而异。(部分信息见6.2.9 节,“设置环境变量”。)修改PATH设置后,请在 Windows 上打开一个新的控制台窗口,或在 Unix 上重新登录,以使设置生效。Consult the documentation for your command interpreter for instructions on setting your PATH variable. The syntax for setting environment variables is interpreter-specific. (Some information is given in Section 6.2.9, “Setting Environment Variables”.) 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.