5.1.13.3 Connecting Using the IPv6 Local Host Address使用IPv6本地主机地址连接

The following procedure shows how to configure MySQL to permit IPv6 connections by clients that connect to the local server using the ::1 local host address. The instructions given here assume that your system supports IPv6.以下过程显示了如何配置MySQL以允许使用::1本地主机地址连接到本地服务器的客户端进行IPv6连接。此处给出的说明假定您的系统支持IPv6。

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

    [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 the local host addresses for both IPv4 and IPv6:此示例指定了IPv4和IPv6的本地主机地址:

    [mysqld]
    bind_address = 127.0.0.1,::1

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

  2. As an administrator, connect to the server and create an account for a local user who can connect from the ::1 local IPv6 host address:作为管理员,请连接到服务器并为可以从::1本地IPv6主机地址连接的本地用户创建帐户:

    mysql> CREATE USER 'ipv6user'@'::1' IDENTIFIED BY 'ipv6pass';

    For the permitted syntax of IPv6 addresses in account names, see Section 6.2.4, “Specifying Account Names”. 有关帐户名中IPv6地址的允许语法,请参阅第6.2.4节,“指定帐户名”In addition to the CREATE USER statement, you can issue GRANT statements that give specific privileges to the account, although that is not necessary for the remaining steps in this procedure.除了CREATE USER语句外,您还可以发出GRANT语句,为帐户授予特定权限,尽管对于此过程中的其余步骤来说这不是必需的。

  3. Invoke the mysql client to connect to the server using the new account:使用新帐户调用mysql客户端连接到服务器:

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

    mysql> STATUS
    ...
    Connection:   ::1 via TCP/IP
    ...
    
    mysql> SELECT CURRENT_USER(), @@bind_address;
    +----------------+----------------+
    | CURRENT_USER() | @@bind_address |
    +----------------+----------------+
    | ipv6user@::1   | ::             |
    +----------------+----------------+