10bet网址
MySQL内部手册


14.2.5连接阶段报文

协议::握手

初始握手报文

当客户端连接到服务器时,服务器向客户端发送握手报文。根据服务器版本和配置选项,发送初始数据包的不同变体。

为了允许服务器添加对新协议的支持,第一个字节定义了协议版本。

自3.21.0以来协议::HandshakeV10发送时,它仍然是支持的协议::HandshakeV9带有编译时选项。

有效载荷

1 protocol_version…

协议::HandshakeV10

初始握手包-协议版本10

有效载荷

1 [0a] protocol version string[NUL] server version 4 connection id string[8] auth-plugin-data-part-1 1 [00] filler 2个capability flags(低2个字节),如果报文中有更多的数据:1个字符集2个状态标志2个能力标志(上两个字节)if capabilities & CLIENT_PLUGIN_AUTH {1 auth-plugin-data的长度}else {1 [00]} string[10]保留(所有[00])if capabilities & CLIENT_SECURE_CONNECTION {string[$len] auth-plugin-data-part-2 ($len=MAX(13, auth-plugin-data的长度- 8))if capabilities & CLIENT_PLUGIN_AUTH {string[NUL] auth-plugin name}

字段

  • protocol_version1) - - -0 x0aprotocol_version

  • server_version字符串。空)——人类可读的服务器版本

  • connection_id4——连接id

  • auth_plugin_data_part_1string.fix_len——[len=8] auth-plugin数据的前8个字节

  • filler_11) - - -0 x00

  • capability_flag_12的下2个字节协议::CapabilityFlags(可选)

  • character_set1)——默认的服务器字符集,只有较低的8位协议::CharacterSet(可选)

    字符集value实际上是一个排序规则ID,但隐含字符集;看到协议::CharacterSet描述。

  • status_flags2) - - -协议::StatusFlags(可选)

  • capability_flags_22的上2个字节协议::CapabilityFlags

  • auth_plugin_data_len1——如果auth_plugin_data_len为> 0,则组合auth_plugin_data的长度

  • auth_plugin_name字符串。空)——auth_plugin_data所属的auth_method的名称

    请注意

    由于错误# 59453在5.5.10和5.6.2之前的版本中,auth-plugin-name缺少终止符null -char。

返回

协议::HandshakeResponse来自客户端

所实现的

send_server_handshake_packet ()

例子

36 00 00 00 0a 35 2e 35 2e 32 2d 6d 32 00 0b 00 6....5.5.2-m2…00 00 64 76 48 40 49 2d 43 4a 00 ff f7 08 02 00 ..dvH@I-CJ.....。00 00 00 00 00 00 00 00 00 00 00 00 2a 34 64 .............*4d 7c 63 5a 77 6b 34 5e 5d 3a 00 bb0 ^]:。

如果CLIENT_PLUGIN_AUTH设置服务器发送的名称身份验证方法这一auth_plugin_data属于:

50 000 00 00 0a 35 2e 36 2e 34 2d 6d 37 2d 6c 6f P....5.6.4-m7-lo 67 00 56 0a 00 52 42 33 76 7a 26 47 72 00 ff g.V…RB3vz&Gr..Ff 08 02 00 0f c0 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................00 2b 79 44 26 2f 5a 5a 33 30 35 5a 47 00 6d 79 .+yD&/ZZ305ZG。我的73 71 6c 5f 6e 61 74 69 76 65 5f 70 61 73 73 77 sql_native_passw 6f 72 64 400 ord
请注意

auth-plugin-data是串的连接吗auth-plugin-data-part-1而且auth-plugin-data-part-2

请注意

只有田野上去了填料auth_plugin_data_part_1是必需的,所有其他字段都是可选的。

协议::HandshakeV9:

初始握手包-协议版本9

有效载荷

1 [09] protocol_version string[NUL] server_version 4 connection_id string[NUL] scramble .输出说明

字段

返回

协议::HandshakeResponse320

协议::HandshakeResponse:

取决于服务器的支持CLIENT_PROTOCOL_41能力和客户端对标志的理解客户端必须发送一个协议::HandshakeResponse41协议::HandshakeResponse320

协议::HandshakeResponse41:

支持4.1+客户端发送的握手响应报文CLIENT_PROTOCOL_41如果服务器在它的初始握手包中宣布它。否则(与旧服务器通信)协议::HandshakeResponse320必须使用数据包。

有效载荷

4个能力标志,CLIENT_PROTOCOL_41 always set 4 maximum -packet size 1 character set string[23] reserved (all [0]) string[NUL] username if capabilities & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA {lenent -int auth-response string的长度[n] auth-response} else if capabilities & CLIENT_SECURE_CONNECTION {1 auth-response string的长度[n] auth-response} else {string[NUL] auth-response} if capabilities & CLIENT_CONNECT_WITH_DB {string[NUL] database} if capabilities & CLIENT_PLUGIN_AUTH {string[NUL] auth pluginname} if capabilities & CLIENT_CONNECT_ATTRS {lenent -int所有键值的长度lenent -str key lenent -str value if-more data in 'length of all key-value ',更多的键和值对}

字段

  • capability_flags4中定义的客户端的能力标志协议::CapabilityFlags

  • max_packet_size4)——客户端想要发送给服务器的命令包的最大大小

  • character_set1中定义的连接的默认字符集协议::CharacterSet

  • 用户名string.fix_len)——客户端想要登录的SQL帐户的名称——这个字符串应该使用表示的字符集来解释字符集字段。

  • auth-response字符串。空生成的不透明认证响应数据身份验证方法插件名称字段。

  • 数据库字符串。空)——initail数据库的连接——该字符串应该解释使用的字符集指示字符集字段。

  • Auth插件名称字符串。空)——身份验证方法由客户端用于生成auth-response值。这是一个UTF-8字符串。

例子

MySQL 5.5.8 withCLIENT_PROTOCOL_41CLIENT_PLUGIN_AUTHCLIENT_SECURE_CONNECTION,CLIENT_CONNECT_WITH_DBSet,它看起来像:

54 00 01 8d a6 0f 00 00 00 00 00 00 00 01 08 00 00 00 T...............00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................00 00 00 70 61 6d 00 14 ab 09 ee f6 BC b1 32 ....pam........2 3e 61 14 38 65 c0 99 1d 95 7d 75 d4 47 74 65 73 >a.8e....}u。Gtes 74 00 6d 79 73 71 6c 5f 6e 61 74 69 76 65 5f 70 t.mysql_native_p 61 73 73 77 6f 72 64 400 assword。

从MySQL 5.6.6开始,客户端可以发送属性,如果CLIENT_CONNECT_ATTRS设置:

B2 00 00 01 85 a2 1e 00 00 00 00 00 40 08 00 00 00 ...........@...。00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................00 00 00 72 6f 6f 74 00 14 22 50 79 a2 12 d4 ....root. "Py…E8 82 e5 b3 f4 1a 97 75 6b c8 be db 9f 80 6d 79 .......uk.....My 73 71 6c 5f 6e 61 74 69 76 65 5f 70 61 73 73 77 sql_native_passw 6f 72 64 00 61 03 5f 6f 73 09 64 65 62 69 61 6e ord.a._os.debian 36 2e 30 0c 5f 63 6c 69 65 6e 74 5f 6e 61 6d 65 6.0。.libmysql._pid. _client_name 08 6c 69 62 6d 79 73 71 6c 04 5f 70 69 64 05 32。2 32 33 34 34 0f 5f 63 6c 69 65 6e 74 5f 76 65 72 2344。_client_ver 73 69 6f 6e 08 35 2e 36 2e 36 2d 6d 39 09 5f 70 sion.5.6.6-m9。_p 6c 61 74 66 6f 72 6d 06 78 38 36 5f 36 34 03 66 latform.x86_64。F 6f 6f 03 62 61 72 oo.bar
谨慎

目前不支持UCS2、UTF16和UTF32等多字节字符集。

请注意

如果客户端希望有一个安全的SSL连接并设置CLIENT_SSL标志,它应该首先发送SSL请求报文只有在建立了安全连接之后,它才应该发送握手响应包。

协议::HandshakeResponse320:

旧的握手响应包被旧的客户端使用,或者如果服务器不支持CLIENT_PROTOCOL_41能力。

有效载荷

2个能力标志,CLIENT_PROTOCOL_41 never set 3 max-packet size string[NUL] username if capabilities & CLIENT_CONNECT_WITH_DB {string[NUL] auth-response string[NUL] database} else {string[EOF] auth-response}

字段

  • capability_flags2中定义的客户端的能力标志协议::CapabilityFlags

  • max_packet_size3.)——客户端想要发送给服务器的命令包的最大大小

  • auth-response字符串。空生成的不透明认证响应数据身份验证方法插件名称字段。

  • 数据库字符串。空)——initail数据库的连接——该字符串应该解释使用的字符集指示字符集字段。

例子

11 00 00 01 85 24 00 00 00 00 6f 6c 64 00 47 44 53 .....$…old。GDS 43 51 59 52 5f CQYR_
请注意

如果auth-responseField后面跟着a数据库字段必须以0结尾。

协议::SSLRequest:

SSL连接请求报文。它类似于握手响应包,但在此之前被截断用户名字段。如果服务器支持CLIENT_SSL能力,客户端可以发送这个数据包请求一个安全的SSL连接。的CLIENT_SSLcapability标志必须在SSL连接请求包中设置。

有效载荷

4个能力标志,CLIENT_SSL始终设置4个最大数据包大小1个字符集字符串[23]保留(所有[0])

协议::AuthSwitchRequest:

认证方式切换请求报文。如果服务器和客户端都支持CLIENT_PLUGIN_AUTH能力,服务器可以发送此包要求客户端使用另一种身份验证方法。

有效载荷

1 [fe] string[NUL] plugin name string[EOF] auth plugin数据

字段

  • 状态1) - - -以0 xfe

  • auth_method_name字符串。空)——要切换到的认证方法的名称

  • auth_method_data字符串。EOF)——该身份验证方法的初始auth-data

返回

协议::AuthSwitchResponse或连接关闭

例子

如果CLIENT_PLUGIN_AUTH设置,服务器希望客户机使用身份验证:Native41它发送的方法:

2c 00 00 02 fe 6d 79 73 71 6c 5f 6e 61 74 69 76,....mysql_nativ 65 5f 70 61 73 73 77 6f 72 64 00 7a 51 67 34 69 e_password.zQg4i 36 6f 4e 79 36 3d 72 48 4e 2f 3e 2d 62 29 41 00 6oNy6=rHN/>-b)A.

协议::OldAuthSwitchRequest:

Old Authentication Method Switch Request报文,由单个0xfe字节组成。它由服务器发送,请求客户端切换到旧密码认证如果CLIENT_PLUGIN_AUTH功能不支持(客户机或服务器)

有效载荷

1(铁)

字段

状态1) - - -以0 xfe

返回

协议::AuthSwitchResponse使用旧密码哈希

例子

01 00 00 02 fe

协议::AuthSwitchResponse:

认证方法切换响应报文,包含认证方法切换请求报文中请求的认证方法产生的响应数据。该数据对协议是不透明的。

有效载荷

字符串[EOF] auth插件响应

字段

数据字符串。EOF)——认证响应数据

返回

协议::AuthMoreDataOK_PacketERR_Packet

例子

如果客户端发送一个mysql_native_password响应,但是服务器有一个mysql_old_password对于该用户,它将要求客户端切换到mysql_old_password客户会回复:

09 00 00 03 5c 49 4d 5e 4e 58 4f 47 00 ....\IM^NXOG。

在这种情况下,情况正好相反。mysql——default-auth = mysql_old_password对一个mysql_native_password用户),客户端将响应mysql_native_password插件:

14 00 00 03 f4 17 96 1f 79 f3 ac 10 0b da a6 b3 ........y.......b5 c2 0e ab 59 85 ff b8 ....Y…

更多例子见认证方式开关

协议::AuthMoreData:

有效载荷

1 [01] string[EOF]插件数据

字段

  • 状态1) - - -0 x01

  • auth_method_data字符串。EOF)—超出初始挑战的额外auth数据