对于使用 MySQL 客户端库的程序(例如 mysql 和 mysqldump),MySQL 支持基于多种传输协议与服务器的连接:TCP/IP、Unix 套接字文件、命名管道和共享内存。本节介绍如何选择这些协议,以及它们的相似之处和不同之处。For programs that use the MySQL client library (for example, mysql and mysqldump), MySQL supports connections to the server based on several transport protocols: TCP/IP, Unix socket file, named pipe, and shared memory. This section describes how to select these protocols, and how they are similar and different.
对于给定的连接,如果传输协议没有明确指定,则会隐式确定。例如,连接到 localhost 会在 Unix 和类 Unix 系统上生成一个套接字文件连接,否则将连接到 127.0.0.1 的 TCP/IP 连接。更多信息,请参见 第 6.2.4 节,“使用命令选项连接到 MySQL 服务器”。For a given connection, if the transport protocol is not
specified explicitly, it is determined implicitly. For example,
connections to localhost result in a socket
file connection on Unix and Unix-like systems, and a TCP/IP
connection to 127.0.0.1 otherwise. For
additional information, see Section 6.2.4, “Connecting to the MySQL Server Using Command Options”.
要明确指定协议,请使用 --protocol 命令选项。下表显示了 --protocol 的可允许值,并指出每个值适用的平台。值不区分大小写。To specify the protocol explicitly, use the
--protocol command option. The
following table shows the permissible values for
--protocol and indicates the
applicable platforms for each value. The values are not
case-sensitive.
--protocol 值--protocol Value |
使用的传输协议Transport Protocol Used | 适用平台Applicable Platforms |
|---|---|---|
TCP |
TCP/IP | 所有系统All |
SOCKETSOCKET |
Unix 套接字文件Unix socket file | Unix 及类 Unix 系统Unix and Unix-like systems |
PIPEPIPE |
命名管道Named pipe | 窗口Windows |
MEMORYMEMORY |
共享内存Shared memory | 窗口Windows |
TCP/IP 传输支持连接到本地或远程 MySQL 服务器。TCP/IP transport supports connections to local or remote MySQL servers.
套接字文件、命名管道和共享内存传输仅支持连接到本地 MySQL 服务器。(命名管道传输确实允许远程连接,但该功能在 MySQL 中尚未实现。)Socket-file, named-pipe, and shared-memory transports support connections only to local MySQL servers. (Named-pipe transport does allow for remote connections, but this capability is not implemented in MySQL.)
如果未明确指定传输协议,localhost 的解释如下:If the transport protocol is not specified explicitly,
localhost is interpreted as follows:
在 Unix 及类 Unix 系统上,连接到
localhost会导致一个套接字文件连接。On Unix and Unix-like systems, a connection tolocalhostresults in a socket-file connection.否则,连接到
localhost会导致一个到127.0.0.1的 TCP/IP 连接。Otherwise, a connection tolocalhostresults in a TCP/IP connection to127.0.0.1.
如果明确指定了传输协议,localhost 会根据该协议进行解释。例如,使用 --protocol=TCP 时,连接到 localhost 会在所有平台上导致一个到 127.0.0.1 的 TCP/IP 连接。If the transport protocol is specified explicitly,
localhost is interpreted with respect to that
protocol. For example, with
--protocol=TCP, a connection to
localhost results in a TCP/IP connection to
127.0.0.1 on all platforms.
TCP/IP 和套接字文件传输受 TLS/SSL 加密保护,使用在 用于加密连接的命令选项 中描述的选项。命名管道和共享内存传输不受 TLS/SSL 加密保护。TCP/IP and socket-file transports are subject to TLS/SSL encryption, using the options described in Command Options for Encrypted Connections. Named-pipe and shared-memory transports are not subject to TLS/SSL encryption.
如果通过默认安全的传输协议建立连接,则连接默认是安全的。否则,对于需要 TLS/SSL 加密的协议,可以通过加密使连接安全:A connection is secure by default if made over a transport protocol that is secure by default. Otherwise, for protocols that are subject to TLS/SSL encryption, a connection may be made secure using encryption:
TCP/IP 连接默认不是安全的,但可以通过加密使其安全。TCP/IP connections are not secure by default, but can be encrypted to make them secure.
Socket 文件连接默认是安全的。它们也可以加密,但加密 Socket 文件连接不会使其更安全,反而会增加 CPU 负载。Socket-file connections are secure by default. They can also be encrypted, but encrypting a socket-file connection makes it no more secure and increases CPU load.
命名管道连接默认情况下不安全,也不会通过加密来保证安全。然而,可以使用
named_pipe_full_access_group系统变量来控制允许使用命名管道连接的 MySQL 用户。Named-pipe connections are not secure by default, and are not subject to encryption to make them secure. However, thenamed_pipe_full_access_groupsystem variable is available to control which MySQL users are permitted to use named-pipe connections.共享内存连接默认是安全的。Shared-memory connections are secure by default.
如果启用了 require_secure_transport 系统变量,服务器仅允许使用某种形式安全传输的连接。根据前述说明,使用 TLS/SSL 加密的 TCP/IP、套接字文件或共享内存的连接都是安全连接。未使用 TLS/SSL 加密的 TCP/IP 连接以及命名管道连接则不安全。If the require_secure_transport
system variable is enabled, the server permits only connections
that use some form of secure transport. Per the preceding
remarks, connections that use TCP/IP encrypted using TLS/SSL, a
socket file, or shared memory are secure connections. TCP/IP
connections not encrypted using TLS/SSL and named-pipe
connections are not secure.
另请参阅 将加密连接配置为必需。See also Configuring Encrypted Connections as Mandatory.
所有传输协议都可以在客户端与服务器之间的流量上使用压缩。如果在给定连接中同时使用压缩和加密,则压缩会在加密之前进行。有关更多信息,请参见 第 6.2.8 节,“连接压缩控制”。All transport protocols are subject to use of compression on the traffic between the client and server. If both compression and encryption are used for a given connection, compression occurs before encryption. For more information, see Section 6.2.8, “Connection Compression Control”.