5.1.13.4 Connecting Using IPv6 Nonlocal Host Addresses使用IPv6非本地主机地址连接

The following procedure shows how to configure MySQL to permit IPv6 connections by remote clients. It is similar to the preceding procedure for local clients, but the server and client hosts are distinct and each has its own nonlocal IPv6 address. The example uses these addresses:以下过程显示了如何配置MySQL以允许远程客户端进行IPv6连接。它类似于前面针对本地客户端的过程,但服务器和客户端主机是不同的,每个主机都有自己的非本地IPv6地址。该示例使用以下地址:

Server host: 2001:db8:0:f101::1
Client host: 2001:db8:0:f101::2

These addresses are chosen from the nonroutable address range recommended by IANA for documentation purposes and suffice for testing on your local network. 这些地址是从IANA出于文档目的推荐的不可路由地址范围中选择的,足以在您的本地网络上进行测试。To accept IPv6 connections from clients outside the local network, the server host must have a public address. 要接受来自本地网络外部客户端的IPv6连接,服务器主机必须具有公共地址。If your network provider assigns you an IPv6 address, you can use that. Otherwise, another way to obtain an address is to use an IPv6 broker; see Section 5.1.13.5, “Obtaining an IPv6 Address from a Broker”.如果您的网络提供商为您分配了IPv6地址,您可以使用该地址。否则,获取地址的另一种方法是使用IPv6代理;请参阅第5.1.13.5节,“从代理获取IPv6地址”

  1. Start the MySQL server with an appropriate bind_address setting to permit it to accept IPv6 connections. 使用适当的bind_address设置启动MySQL服务器,以允许其接受IPv6连接。For example, put the following lines in the server option file and restart the server:例如,将以下行放入服务器选项文件中并重新启动服务器:

    [mysqld]
    bind_address = *

    Specifying * (or ::) as the value for bind_address permits both IPv4 and IPv6 connections on all server host IPv4 and IPv6 interfaces. 指定*(或::)作为bind_address的值,允许在所有服务器主机IPv4和IPv6接口上进行IPv4和IPv6连接。If you want to bind the server to a specific list of addresses, you can do this as of MySQL 8.0.13 by specifying a comma-separated list of values for bind_address. 如果你想将服务器绑定到特定的地址列表,从MySQL 8.0.13开始,你可以通过为bind_address指定一个逗号分隔的值列表来实现。This example specifies an IPv4 address as well as the required server host IPv6 address:此示例指定了IPv4地址以及所需的服务器主机IPv6地址:

    [mysqld]
    bind_address = 198.51.100.20,2001:db8:0:f101::1

    For more information, see the bind_address description in Section 5.1.8, “Server System Variables”.有关更多信息,请参阅第5.1.8节,“服务器系统变量”中的bind_address描述。

  2. On the server host (2001:db8:0:f101::1), create an account for a user who can connect from the client host (2001:db8:0:f101::2):在服务器主机(2001:db8:0:f101::1)上,为可以从客户端主机(2001:db8:0:f101::2)连接的用户创建一个帐户:

    mysql> CREATE USER 'remoteipv6user'@'2001:db8:0:f101::2' IDENTIFIED BY 'remoteipv6pass';
  3. On the client host (2001:db8:0:f101::2), invoke the mysql client to connect to the server using the new account:在客户端主机(2001:db8:0:f101::2)上,调用mysql客户端,使用新帐户连接到服务器:

    shell> mysql -h 2001:db8:0:f101::1 -u remoteipv6user -premoteipv6pass
  4. Try some simple statements that show connection information:尝试一些显示连接信息的简单语句:

    mysql> STATUS
    ...
    Connection:   2001:db8:0:f101::1 via TCP/IP
    ...
    
    mysql> SELECT CURRENT_USER(), @@bind_address;
    +-----------------------------------+----------------+
    | CURRENT_USER()                    | @@bind_address |
    +-----------------------------------+----------------+
    | remoteipv6user@2001:db8:0:f101::2 | ::             |
    +-----------------------------------+----------------+