This section describes use of URI-like connection strings or key-value pairs to specify how to establish connections to the MySQL server, for clients such as MySQL Shell. 本节介绍如何使用类似URI的连接字符串或键值对来指定如何为MySQL Shell等客户端建立与MySQL服务器的连接。For information on establishing connections using command-line options, for clients such as mysql or mysqldump, see Section 4.2.4, “Connecting to the MySQL Server Using Command Options”. 有关使用命令行选项建立连接的信息,对于mysql或mysqldump等客户端,请参阅第4.2.4节,“使用命令选项连接到mysql服务器”。For additional information if you are unable to connect, see Section 6.2.21, “Troubleshooting Problems Connecting to MySQL”.如果您无法连接,有关更多信息,请参阅第6.2.21节,“连接到MySQL的故障排除”。
The term “URI-like” signifies connection-string syntax that is similar to but not identical to the URI (uniform resource identifier) syntax defined by RFC 3986.术语“类URI”表示与RFC 3986定义的URI(一致性资源标识符)语法相似但不完全相同的连接字符串语法。
The following MySQL clients support connecting to a MySQL server using a URI-like connection string or key-value pairs:以下MySQL客户端支持使用类似URI的连接字符串或键值对连接到MySQL服务器:
MySQL Shell
MySQL Connectors which implement X DevAPI实现X DevAPI的MySQL连接器
This section documents all valid URI-like string and key-value pair connection parameters, many of which are similar to those specified with command-line options:本节记录了所有有效的URI,如字符串和键值对连接参数,其中许多与使用命令行选项指定的参数相似:
Parameters specified with a URI-like string use a syntax such as 使用类似URI的字符串指定的参数使用以下语法myuser@example.com:3306/main-schema
. myuser@example.com:3306/main-schema
。For the full syntax, see Connecting Using URI-Like Connection Strings.有关完整语法,请参阅使用类似URI的连接字符串进行连接。
Parameters specified with key-value pairs use a syntax such as 使用键值对指定的参数使用诸如{user:'myuser', host:'example.com', port:3306, schema:'main-schema'}
. {user:'myuser', host:'example.com', port:3306, schema:'main-schema'}
之类的语法。For the full syntax, see Connecting Using Key-Value Pairs.有关完整语法,请参阅使用键值对连接。
Connection parameters are not case-sensitive. Each parameter, if specified, can be given only once. If a parameter is specified more than once, an error occurs.连接参数不区分大小写。如果指定了每个参数,则只能给出一次。如果参数被指定多次,则会发生错误。
This section covers the following topics:本节涵盖以下主题:
The following discussion describes the parameters available when specifying a connection to MySQL. 以下讨论描述了指定MySQL连接时可用的参数。These parameters can be provided using either a string that conforms to the base URI-like syntax (see Connecting Using URI-Like Connection Strings), or as key-value pairs (see Connecting Using Key-Value Pairs).这些参数可以使用符合类基URI语法的字符串提供(请参阅使用类URI连接字符串进行连接),也可以作为键值对提供(请参阅使用键值对进行连接)。
scheme
: The transport protocol to use. Use :要使用的传输协议。使用mysqlx
for X Protocol connections and mysql
for classic MySQL protocol connections. mysqlx
进行X协议连接,使用mysql
进行经典mysql协议连接。If no protocol is specified, the server attempts to guess the protocol. 如果没有指定协议,服务器将尝试猜测该协议。Connectors that support DNS SRV can use the 支持DNS SRV的连接器可以使用mysqlx+srv
scheme (see Connections Using DNS SRV Records).mysqlx+srv
方案(请参阅使用DNS SRV记录的连接)。
user
: The MySQL user account to provide for the authentication process.:为身份验证过程提供的MySQL用户帐户。
password
: The password to use for the authentication process.:用于身份验证过程的密码。
Specifying an explicit password in the connection specification is insecure and not recommended. Later discussion shows how to cause an interactive prompt for the password to occur.在连接规范中指定显式密码是不安全的,不建议这样做。稍后的讨论将显示如何使密码出现交互式提示。
host
: The host on which the server instance is running. The value can be a host name, IPv4 address, or IPv6 address. :运行服务器实例的主机。该值可以是主机名、IPv4地址或IPv6地址。If no host is specified, the default is 如果未指定主机,则默认为localhost。localhost
.
port
: The TCP/IP network port on which the target MySQL server is listening for connections. If no port is specified, the default is 33060 for X Protocol connections and 3306 for classic MySQL protocol connections.:目标MySQL服务器正在侦听连接的TCP/IP网络端口。如果未指定端口,则X协议连接的默认端口为33060,经典MySQL协议连接的缺省端口为3306。
socket
: The path to a Unix socket file or the name of a Windows named pipe. Values are local file paths. :Unix套接字文件的路径或Windows命名管道的名称。值是本地文件路径。In URI-like strings, they must be encoded, using either percent encoding or by surrounding the path with parentheses. 在类URI字符串中,必须使用百分比编码或用括号括住路径对其进行编码。Parentheses eliminate the need to percent encode characters such as the 括号消除了对/
directory separator character. /
目录分隔符等字符进行百分比编码的需要。For example, to connect as 例如,连接为root@localhost
using the Unix socket /tmp/mysql.sock
, specify the path using percent encoding as root@localhost?socket=%2Ftmp%2Fmysql.sock
, or using parentheses as root@localhost?socket=(/tmp/mysql.sock)
.root@localhost
使用Unix套接字/tmp/mysql.sock
,使用百分比编码指定路径为root@localhost?socket=%2Ftmp%2Fmysql.sock
,或使用括号作为root@localhost?socket=(/tmp/mysql.sock)
。
schema
: The default database for the connection. If no database is specified, the connection has no default database.:连接的默认数据库。如果未指定数据库,则连接没有默认数据库。
The handling of Unix上localhost
on Unix depends on the type of transport protocol. localhost
的处理取决于传输协议的类型。Connections using classic MySQL protocol handle 使用经典MySQL协议的连接处理localhost
the same way as other MySQL clients, which means that localhost
is assumed to be for socket-based connections. localhost
的方式与其他MySQL客户端相同,这意味着假设localhost
用于基于套接字的连接。For connections using X Protocol, the behavior of 对于使用X协议的连接,localhost
differs in that it is assumed to represent the loopback address, for example, IPv4 address 127.0.0.1.localhost
的行为不同,因为它被假设为表示环回地址,例如IPv4地址127.0.0.1。
You can specify options for the connection, either as attributes in a URI-like string by appending 您可以为连接指定选项,也可以通过附加类似URI的字符串中的属性来指定?
, or as key-value pairs. The following options are available:attribute=value
?attribute=value
或作为键值对。以下选项可用:
ssl-mode
: The desired security state for the connection. The following modes are permissible::连接所需的安全状态。允许使用以下模式:
DISABLED
PREFERRED
REQUIRED
VERIFY_CA
VERIFY_IDENTITY
For information about these modes, see the 有关这些模式的信息,请参阅加密连接的命令选项中的--ssl-mode
option description in Command Options for Encrypted Connections.--ssl-mode
选项描述。
ssl-ca
: The path to the X.509 certificate authority file in PEM format.:PEM格式的X.509证书颁发机构文件的路径。
ssl-capath
: The path to the directory that contains the X.509 certificates authority files in PEM format.:包含PEM格式的X.509证书颁发机构文件的目录路径。
ssl-cert
: The path to the X.509 certificate file in PEM format.:PEM格式的X.509证书文件的路径。
ssl-cipher
: The encryption cipher to use for connections that use TLS protocols up through TLSv1.2.:用于通过TLSv1.2使用TLS协议的连接的加密密码。
ssl-crl
: The path to the file that contains certificate revocation lists in PEM format.:包含PEM格式证书吊销列表的文件的路径。
ssl-crlpath
: The path to the directory that contains certificate revocation-list files in PEM format.:包含PEM格式的证书吊销列表文件的目录的路径。
ssl-key
: The path to the X.509 key file in PEM format.:PEM格式的X.509密钥文件的路径。
tls-version
: The TLS protocols permitted for classic MySQL protocol encrypted connections. :TLS协议允许经典MySQL协议加密连接。This option is supported by MySQL Shell only. 仅MySQL Shell支持此选项。The value of tls-version
(singular) is a comma separated list, for example TLSv1.1,TLSv1.2
. tls-version
(单数)的值是一个逗号分隔的列表,例如TLSv1.1,TLSv1.2
。For details, see Section 6.3.2, “Encrypted Connection TLS Protocols and Ciphers”. 有关详细信息,请参阅第6.3.2节,“加密连接TLS协议和密码”。This option depends on the 此选项取决于ssl-mode
option not being set to DISABLED
.ssl-mode
选项未设置为DISABLED
。
tls-versions
: The permissible TLS protocols for encrypted X Protocol connections. :用于加密X协议连接的允许TLS协议。The value of tls-versions
(plural) is an array such as [TLSv1.2,TLSv1.3]
. tls-versions
(复数)的值是一个数组,如[TLSv1.2,TLSv1.3]
。For details, see Section 6.3.2, “Encrypted Connection TLS Protocols and Ciphers”. 有关详细信息,请参阅第6.3.2节,“加密连接TLS协议和密码”。This option depends on the 此选项取决于ssl-mode
option not being set to DISABLED
.ssl-mode
选项未设置为DISABLED
。
tls-ciphersuites
: The permitted TLS cipher suites. :允许的TLS密码套件。The value of tls-ciphersuites
is a list of IANA cipher suite names as listed at TLS Ciphersuites. tls-ciphersuites
的值是tls密码套件中列出的IANA密码套件名称列表。For details, see Section 6.3.2, “Encrypted Connection TLS Protocols and Ciphers”. 有关详细信息,请参阅第6.3.2节,“加密连接TLS协议和密码”。This option depends on the 此选项取决于ssl-mode
option not being set to DISABLED
.ssl-mode
选项未设置为DISABLED
。
auth-method
: The authentication method to use for the connection. The default is :用于连接的身份验证方法。默认值为AUTO
, meaning that the server attempts to guess. The following methods are permissible:AUTO
,这意味着服务器会尝试猜测。允许使用以下方法:
AUTO
MYSQL41
SHA256_MEMORY
FROM_CAPABILITIES
FALLBACK
PLAIN
For X Protocol connections, any configured 对于X协议连接,任何配置的auth-method
is overridden to this sequence of authentication methods: MYSQL41
, SHA256_MEMORY
, PLAIN
.auth-method
都被重写为以下身份验证方法序列:MYSQL41
、SHA256_MEMORY
、PLAIN
。
get-server-public-key
: Request from the server the public key required for RSA key pair-based password exchange. :从服务器请求基于RSA密钥对的密码交换所需的公钥。Use when connecting to MySQL 8.0 servers over classic MySQL protocol with SSL mode 在SSL模式DISABLED
. You must specify the protocol in this case. For example:DISABLED
的情况下,通过经典MySQL协议连接到MySQL 8.0服务器时使用。在这种情况下,您必须指定协议。例如:
mysql://user@localhost:3306?get-server-public-key=true
This option applies to clients that authenticate with the 此选项适用于使用caching_sha2_password
authentication plugin. For that plugin, the server does not send the public key unless requested. caching_sha2_password
身份验证插件进行身份验证的客户端。对于该插件,除非请求,否则服务器不会发送公钥。This option is ignored for accounts that do not authenticate with that plugin. 对于不使用该插件进行身份验证的帐户,此选项将被忽略。It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the server using a secure connection.如果不使用基于RSA的密码交换,它也会被忽略,就像客户端使用安全连接连接到服务器的情况一样。
If 如果给定了server-public-key-path=
is given and specifies a valid public key file, it takes precedence over file_name
get-server-public-key
.server-public-key-path=file_name
并指定了有效的公钥文件,则它优先于获取服务器公钥。
For information about the 有关caching_sha2_password
plugin, see Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.caching_sha2_password
插件的信息,请参阅第6.4.1.2节,“缓存SHA-2可插拔身份验证”。
server-public-key-path
: The path name to a file in PEM format containing a client-side copy of the public key required by the server for RSA key pair-based password exchange. :PEM格式文件的路径名,该文件包含服务器基于RSA密钥对进行密码交换所需的公钥客户端副本。Use when connecting to MySQL 8.0 servers over classic MySQL protocol with SSL mode 在SSL模式DISABLED
.DISABLED
的情况下,通过经典MySQL协议连接到MySQL 8.0服务器时使用。
This option applies to clients that authenticate with the 此选项适用于使用sha256_password
or caching_sha2_password
authentication plugin. This option is ignored for accounts that do not authenticate with one of those plugins. sha256_password
或caching_sha2_password
身份验证插件进行身份验证的客户端。对于未使用这些插件之一进行身份验证的帐户,此选项将被忽略。It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the server using a secure connection.如果不使用基于RSA的密码交换,它也会被忽略,就像客户端使用安全连接连接到服务器的情况一样。
If 如果给定了server-public-key-path=
is given and specifies a valid public key file, it takes precedence over file_name
get-server-public-key
.server-public-key-path=file_name
并指定了有效的公钥文件,则它优先于获取服务器公钥。
For information about the 有关sha256_password
and caching_sha2_password
plugins, see Section 6.4.1.3, “SHA-256 Pluggable Authentication”, and Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.sha256_password
和caching_sha2_password
插件的信息,请参阅第6.4.1.3节,“SHA-256可插拔身份验证”和第6.4.1.2节,“缓存SHA-2可插拔身份认证”。
connect-timeout
: An integer value used to configure the number of seconds that clients, such as MySQL Shell, wait until they stop trying to connect to an unresponsive MySQL server.:一个整数值,用于配置客户端(如MySQL Shell)在停止尝试连接到无响应的MySQL服务器之前等待的秒数。
compression
: This option requests or disables compression for the connection. Up to MySQL 8.0.19 it operates for classic MySQL protocol connections only, and from MySQL 8.0.20 it also operates for X Protocol connections.:此选项请求或禁用连接的压缩。在MySQL 8.0.19之前,它仅适用于经典MySQL协议连接,从MySQL 8.0.20开始,它也适用于X协议连接。
Up to MySQL 8.0.19, the values for this option are 在MySQL 8.0.19之前,此选项的值为true
(or 1) which enables compression, and the default false
(or 0) which disables compression.true
(或1),表示启用压缩,默认值为false
(或0),表示禁用压缩。
From MySQL 8.0.20, the values for this option are 从MySQL 8.0.20开始,此选项的值是required
, which requests compression and fails if the server does not support it; preferred
, which requests compression and falls back to an uncompressed connection; and disabled
, which requests an uncompressed connection and fails if the server does not permit those. required
,如果服务器不支持压缩,则请求压缩失败;preferred
是请求压缩并回退到未压缩的连接;disabled
请求未压缩的连接,如果服务器不允许,则失败。preferred
is the default for X Protocol connections, and disabled
is the default for classic MySQL protocol connections. preferred
是X协议连接的默认值,disabled
是经典MySQL协议连接的缺省值。For information on X Plugin connection compression control, see Section 20.5.5, “Connection Compression with X Plugin”.有关X插件连接压缩控制的信息,请参阅第20.5.5节,“使用X插件的连接压缩”。
Note that different MySQL clients implement their support for connection compression differently. Consult your client's documentation for details.请注意,不同的MySQL客户端对连接压缩的支持实现方式不同。有关详细信息,请参阅客户的文档。
compression-algorithms
and 和compression-level
: These options are available in MySQL Shell 8.0.20 and later for more control over connection compression. :MySQL Shell 8.0.20及更高版本中提供了这些选项,以更好地控制连接压缩。You can specify them to select the compression algorithm used for the connection, and the numeric compression level used with that algorithm. 您可以指定它们来选择用于连接的压缩算法,以及与该算法一起使用的数字压缩级别。You can also use 您还可以使用compression-algorithms
in place of compression
to request compression for the connection. compression-algorithms
代替compression
来请求对连接进行压缩。For information on MySQL Shell's connection compression control, see Using Compressed Connections.有关MySQL Shell的连接压缩控制的信息,请参阅使用压缩连接。
connection-attributes
: Controls the key-value pairs that application programs pass to the server at connect time. :控制应用程序在连接时传递给服务器的键值对。For general information about connection attributes, see Section 27.12.9, “Performance Schema Connection Attribute Tables”. 有关连接属性的一般信息,请参阅第27.12.9节,“性能模式连接属性表”。Clients usually define a default set of attributes, which can be disabled or enabled. For example:客户端通常定义一组默认属性,可以禁用或启用。例如:
mysqlx://user@host?connection-attributes mysqlx://user@host?connection-attributes=true mysqlx://user@host?connection-attributes=false
The default behavior is to send the default attribute set. Applications can specify attributes to be passed in addition to the default attributes. 默认行为是发送默认属性集。除了默认属性外,应用程序还可以指定要传递的属性。You specify additional connection attributes as a 您可以将其他连接属性指定为connection-attributes
parameter in a connection string. connection-attributes
中的连接属性参数。The connection-attributes
parameter value must be empty (the same as specifying true
), a Boolean
value (true
or false
to enable or disable the default attribute set), or a list or zero or more key=value
specifiers separated by commas (to be sent in addition to the default attribute set). connection-attributes
参数值必须为空(与指定true
相同)、布尔值(启用或禁用默认属性集为true
或false
)、列表或用逗号分隔的零个或多个key=value
说明符(除默认属性集外还将发送)。Within a list, a missing key value evaluates as an empty string. Further examples:在列表中,缺少的键值计算结果为空字符串。其他示例:
mysqlx://user@host?connection-attributes=[attr1=val1,attr2,attr3=] mysqlx://user@host?connection-attributes=[]
Application-defined attribute names cannot begin with 应用程序定义的属性名称不能以_
because such names are reserved for internal attributes._
开头,因为这些名称是为内部属性保留的。
You can specify a connection to MySQL Server using a URI-like string. Such strings can be used with the MySQL Shell with the 您可以使用类似URI的字符串指定到MySQL Server的连接。这些字符串可以与MySQL Shell一起使用,包括--uri
command option, the MySQL Shell \connect
command, and MySQL Connectors which implement X DevAPI.--uri
命令选项、MySQL Shell\connect
命令和实现X DevAPI的MySQL连接器。
The term “URI-like” signifies connection-string syntax that is similar to but not identical to the URI (uniform resource identifier) syntax defined by RFC 3986.术语“类URI”表示与RFC 3986定义的URI(一致性资源标识符)语法相似但不完全相同的连接字符串语法。
A URI-like connection string has the following syntax:类似URI的连接字符串具有以下语法:
[scheme
://][user
[:[password
]]@]host
[:port
][/schema
][?attribute1=value1&attribute2=value2...
Percent encoding must be used for reserved characters in the elements of the URI-like string. 百分比编码必须用于URI元素中的保留字符,如字符串。For example, if you specify a string that includes the 例如,如果指定包含@
character, the character must be replaced by %40
. @
字符的字符串,则该字符必须替换为%40
。If you include a zone ID in an IPv6 address, the 如果在IPv6地址中包含区域ID,则用作分隔符的%
character used as the separator must be replaced with %25
.%
字符必须替换为%25
。
The parameters you can use in a URI-like connection string are described at Base Connection Parameters.您可以在类URI连接字符串中使用的参数在基本连接参数中进行了描述。
MySQL Shell's MySQL Shell的shell.parseUri()
and shell.unparseUri()
methods can be used to deconstruct and assemble a URI-like connection string. shell.parseUri()
和shell.unparseUri()
方法可用于解构和组装类似URI的连接字符串。Given a URI-like connection string, 给定一个类似URI的连接字符串,shell.parseUri()
returns a dictionary containing each element found in the string. shell.parseUri()
返回一个字典,其中包含字符串中找到的每个元素。shell.unparseUri()
converts a dictionary of URI components and connection options into a valid URI-like connection string for connecting to MySQL, which can be used in MySQL Shell or by MySQL Connectors which implement X DevAPI.shell.unparseUri()
将URI组件和连接选项的字典转换为用于连接MySQL的有效URI类连接字符串,该字符串可用于MySQL Shell或实现X DevAPI的MySQL连接器。
If no password is specified in the URI-like string, which is recommended, interactive clients prompt for the password. 如果在类URI字符串中没有指定密码(这是推荐的),则交互式客户端会提示输入密码。The following examples show how to specify URI-like strings with the user name 以下示例显示了如何使用用户名user_name
. In each case, the password is prompted for.user_name
指定类似URI的字符串。在每种情况下,都会提示输入密码。
An X Protocol connection to a local server instance listening at port 33065.与在端口33065监听的本地服务器实例的X协议连接。
mysqlx://user_name
@localhost:33065
A classic MySQL protocol connection to a local server instance listening at port 3333.与在端口3333监听的本地服务器实例的经典MySQL协议连接。
mysql://user_name
@localhost:3333
An X Protocol connection to a remote server instance, using a host name, an IPv4 address, and an IPv6 address.使用主机名、IPv4地址和IPv6地址与远程服务器实例的X协议连接。
mysqlx://user_name
@server.example.com/ mysqlx://user_name
@198.51.100.14:123 mysqlx://user_name
@[2001:db8:85a3:8d3:1319:8a2e:370:7348]
An X Protocol connection using a socket, with the path provided using either percent encoding or parentheses.使用套接字的X协议连接,路径使用百分比编码或括号提供。
mysqlx://user_name
@/path
%2Fto
%2Fsocket.sock
mysqlx://user_name
@(/path/to/socket.sock
)
An optional path can be specified, which represents a database.可以指定表示数据库的可选路径。
# use 'world' as the default database mysqlx://user_name
@198.51.100.1/world # use 'world_x' as the default database, encoding _ as %5F mysqlx://user_name
@198.51.100.2:33060/world%5Fx
An optional query can be specified, consisting of values each given as a 可以指定一个可选的查询,由值组成,每个值都以
pair or as a single key
=value
key
. key=value
对或单个key
的形式给出。To specify multiple values, separate them by 要指定多个值,请用,
characters. ,
字符分隔。A mix of 允许混合使用
and key
=value
key
values is permissible. key=value
和key
值。Values can be of type list, with list values ordered by appearance. 值可以是list类型,列表值按外观排序。Strings must be either percent encoded or surrounded by parentheses. The following are equivalent.字符串必须采用百分比编码或用括号括起来。以下内容是等效的。
ssluser@127.0.0.1?ssl-ca=%2Froot%2Fclientcert%2Fca-cert.pem\ &ssl-cert=%2Froot%2Fclientcert%2Fclient-cert.pem\ &ssl-key=%2Froot%2Fclientcert%2Fclient-key ssluser@127.0.0.1?ssl-ca=(/root/clientcert/ca-cert.pem)\ &ssl-cert=(/root/clientcert/client-cert.pem)\ &ssl-key=(/root/clientcert/client-key)
To specify a TLS version and ciphersuite to use for encrypted connections:要指定用于加密连接的TLS版本和密码套件,请执行以下操作:
mysql://user_name
@198.51.100.2:3306/world%5Fx?\
tls-versions=[TLSv1.2,TLSv1.3]&tls-ciphersuites=[TLS_DHE_PSK_WITH_AES_128_\
GCM_SHA256, TLS_CHACHA20_POLY1305_SHA256]
The previous examples assume that connections require a password. 前面的示例假设连接需要密码。With interactive clients, the specified user's password is requested at the login prompt. 对于交互式客户端,在登录提示时会请求指定用户的密码。If the user account has no password (which is insecure and not recommended), or if socket peer-credential authentication is in use (for example, with Unix socket connections), you must explicitly specify in the connection string that no password is being provided and the password prompt is not required. 如果用户帐户没有密码(这是不安全的,不建议使用),或者正在使用套接字对等凭据身份验证(例如,使用Unix套接字连接),则必须在连接字符串中明确指定不提供密码,也不需要密码提示。To do this, place a 为此,请在字符串中的:
after the user_name
in the string but do not specify a password after it. For example:user_name
后放置一个:
,但不要在其后指定密码。例如:
mysqlx://user_name
:@localhost
In MySQL Shell and some MySQL Connectors which implement X DevAPI, you can specify a connection to MySQL Server using key-value pairs, supplied in language-natural constructs for the implementation. 在MySQL Shell和一些实现X DevAPI的MySQL连接器中,您可以使用键值对指定到MySQL服务器的连接,这些键值对以语言自然构造的形式提供给实现。For example, you can supply connection parameters using key-value pairs as a JSON object in JavaScript, or as a dictionary in Python. 例如,您可以使用键值对作为JavaScript中的JSON对象或Python中的字典来提供连接参数。Regardless of the way the key-value pairs are supplied, the concept remains the same: the keys as described in this section can be assigned values that are used to specify a connection. 无论提供键值对的方式如何,概念都是一样的:本节中描述的键可以被分配用于指定连接的值。You can specify connections using key-value pairs in MySQL Shell's 您可以使用MySQL Shell的shell.connect()
method or InnoDB Cluster's dba.createCluster()
method, and with some of the MySQL Connectors which implement X DevAPI.shell.connect()
方法或InnoDB Cluster的dba.createCluster()
法中的键值对以及实现X DevAPI的一些MySQL连接器来指定连接。
Generally, key-value pairs are surrounded by 通常,键值对被{
and }
characters and the ,
character is used as a separator between key-value pairs. {
和}
字符包围,字符,
用作键值对之间的分隔符。The :
character is used between keys and values, and strings must be delimited (for example, using the '
character). :
字符用于键和值之间,字符串必须分隔(例如,使用'
字符)。It is not necessary to percent encode strings, unlike URI-like connection strings.与类似URI的连接字符串不同,不需要对字符串进行百分比编码。
A connection specified as key-value pairs has the following format:指定为键值对的连接具有以下格式:
{key
:value
,key
:value
, ...}
The parameters you can use as keys for a connection are described at Base Connection Parameters.可以用作连接键的参数在基础连接参数中进行了描述。
If no password is specified in the key-value pairs, which is recommended, interactive clients prompt for the password. 如果建议在键值对中未指定密码,则交互式客户端会提示输入密码。The following examples show how to specify connections using key-value pairs with the user name 以下示例显示了如何使用用户名为'
. user_name
''user_name'
的键值对指定连接。In each case, the password is prompted for.在每种情况下,都会提示输入密码。
An X Protocol connection to a local server instance listening at port 33065.与在端口33065监听的本地服务器实例的X协议连接。
{user:'user_name
', host:'localhost', port:33065}
A classic MySQL protocol connection to a local server instance listening at port 3333.与在端口3333监听的本地服务器实例的经典MySQL协议连接。
{user:'user_name
', host:'localhost', port:3333}
An X Protocol connection to a remote server instance, using a host name, an IPv4 address, and an IPv6 address.使用主机名、IPv4地址和IPv6地址与远程服务器实例的X协议连接。
{user:'user_name
', host:'server.example.com'} {user:'user_name
', host:198.51.100.14:123} {user:'user_name
', host:[2001:db8:85a3:8d3:1319:8a2e:370:7348]}
An X Protocol connection using a socket.使用套接字的X协议连接。
{user:'user_name
', socket:'/path/to/socket/file
'}
An optional schema can be specified, which represents a database.可以指定表示数据库的可选架构。
{user:'user_name
', host:'localhost', schema:'world'}
The previous examples assume that connections require a password. With interactive clients, the specified user's password is requested at the login prompt. 前面的示例假设连接需要密码。对于交互式客户端,在登录提示时会请求指定用户的密码。If the user account has no password (which is insecure and not recommended), or if socket peer-credential authentication is in use (for example, with Unix socket connections), you must explicitly specify that no password is being provided and the password prompt is not required. 如果用户帐户没有密码(这是不安全的,不建议使用),或者正在使用套接字对等凭据身份验证(例如,使用Unix套接字连接),则必须明确指定不提供密码,也不需要密码提示。To do this, provide an empty string using 为此,请在''
after the password
key. For example:password
键后使用''
提供一个空字符串。例如:
{user:'user_name
', password:'', host:'localhost'}