要将客户端程序连接到监听的 MySQL 服务器,而该服务器的网络接口与编译到客户端中的接口不同,您可以使用以下方法之一:To connect with a client program to a MySQL server that is listening to different network interfaces from those compiled into your client, you can use one of the following methods:
使用
--host=host_name--port=启动客户端,以通过 TCP/IP 连接到远程服务器;使用port_number--host=127.0.0.1--port=连接到本地服务器,或者使用port_number--host=localhost--socket=通过 Unix 套接字文件或 Windows 命名管道连接到本地服务器。Start the client withfile_name--host=host_name--port=to connect using TCP/IP to a remote server, withport_number--host=127.0.0.1--port=to connect using TCP/IP to a local server, or withport_number--host=localhost--socket=to connect to a local server using a Unix socket file or a Windows named pipe.file_name使用
--protocol=TCP启动客户端以使用 TCP/IP 连接,使用--protocol=SOCKET通过 Unix 套接字文件连接,使用--protocol=PIPE通过命名管道连接,或使用--protocol=MEMORY通过共享内存连接。对于 TCP/IP 连接,你可能还需要指定--host和--port选项。对于其他类型的连接,你可能需要指定--socket选项以指定 Unix 套接字文件或 Windows 命名管道名称,或--shared-memory-base-name选项以指定共享内存名称。共享内存连接仅在 Windows 上支持。Start the client with--protocol=TCPto connect using TCP/IP,--protocol=SOCKETto connect using a Unix socket file,--protocol=PIPEto connect using a named pipe, or--protocol=MEMORYto connect using shared memory. For TCP/IP connections, you may also need to specify--hostand--portoptions. For the other types of connections, you may need to specify a--socketoption to specify a Unix socket file or Windows named-pipe name, or a--shared-memory-base-nameoption to specify the shared-memory name. Shared-memory connections are supported only on Windows.在 Unix 系统上,在启动客户端之前,设置
MYSQL_UNIX_PORT和MYSQL_TCP_PORT环境变量以指向 Unix 套接字文件和 TCP/IP 端口号。如果您通常使用特定的套接字文件或端口号,可以将设置这些环境变量的命令放入您的.login文件中,这样每次登录时都会应用它们。参见 第 6.9 节,“环境变量”。 On Unix, set theMYSQL_UNIX_PORTandMYSQL_TCP_PORTenvironment variables to point to the Unix socket file and TCP/IP port number before you start your clients. If you normally use a specific socket file or port number, you can place commands to set these environment variables in your.loginfile so that they apply each time you log in. See Section 6.9, “Environment Variables”.在选项文件的
[client]组中指定默认的 Unix 套接字文件和 TCP/IP 端口号。例如,你可以在 Windows 上使用C:\my.cnf,或者在 Unix 的主目录中使用.my.cnf文件。参见 第 6.2.2.2 节,“使用选项文件”。Specify the default Unix socket file and TCP/IP port number in the[client]group of an option file. For example, you can useC:\my.cnfon Windows, or the.my.cnffile in your home directory on Unix. See Section 6.2.2.2, “Using Option Files”.在 C 程序中,您可以在
mysql_real_connect()函数调用中指定套接字文件或端口号参数。您也可以通过调用mysql_options()让程序读取选项文件。参见C API 基本函数说明。In a C program, you can specify the socket file or port number arguments in themysql_real_connect()call. You can also have the program read option files by callingmysql_options(). See C API Basic Function Descriptions.如果您使用 Perl 的
DBD::mysql模块,您可以从 MySQL 选项文件中读取选项。例如:If you are using the PerlDBD::mysqlmodule, you can read options from MySQL option files. For example:$dsn = "DBI:mysql:test;mysql_read_default_group=client;" . "mysql_read_default_file=/usr/local/mysql/data/my.cnf"; $dbh = DBI->connect($dsn, $user, $password);参见第 31.9 节,“MySQL Perl API”。See Section 31.9, “MySQL Perl API”.
其他编程接口可能提供类似的功能来读取选项文件。Other programming interfaces may provide similar capabilities for reading option files.