MySQL 9.0.0
Source Code Documentation
Protocol::HandshakeResponse:

Depending on the servers support for the CLIENT_PROTOCOL_41 capability and the clients understanding of that flag the client has to send either a Protocol::HandshakeResponse320 or Protocol::HandshakeResponse41.

See also
send_client_reply_packet

Protocol::HandshakeResponse320

Old Handshake Response Packet used by old clients or if the server doesn't support CLIENT_PROTOCOL_41 Capabilities Flags flag.

Payload
TypeNameDescription
int<2> client_flag Capabilities Flags, only the lower 16 bits. CLIENT_PROTOCOL_41 should never be set
int<3> max_packet_size maximum packet size, 0xFFFFFF max
string<NUL> username login user name
if capabilities & CLIENT_CONNECT_WITH_DB {
string<NUL> auth-response Opaque authentication response data generated by Authentication Method indicated by the plugin name field.
string<NUL> database initial database for the connection. This string should be interpreted using the character set indicated by character set field.
} else {
string<EOF> auth-response Opaque authentication response data generated by Authentication Method indicated by the plugin name field.
}

Example

11 00 00 01 85 24 00 00 00 6f 6c 64 00 47 44 53 .....$...old.GDS
43 51 59 52 5f CQYR_
Note
If auth-response is followed by a database field it must be NULL terminated.

Protocol::HandshakeResponse41

Handshake Response Packet sent by 4.1+ clients supporting CLIENT_PROTOCOL_41 Capabilities Flags flag, if the server announced it in its Protocol::Handshake. Otherwise (talking to an old server) the Protocol::HandshakeResponse320 packet must be used.

Payload
TypeNameDescription
int<4> client_flag Capabilities Flags, CLIENT_PROTOCOL_41 always set.
int<4> max_packet_size maximum packet size
int<1> character_set client charset a_protocol_character_set, only the lower 8-bits
string[23] filler filler to the size of the handhshake response packet. All 0s.
string<NUL> username login user name
if capabilities & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA {
string<length> auth_response opaque authentication response data generated by Authentication Method indicated by the plugin name field.
} else {
int<1> auth_response_length length of auth_response
string<length> auth_response opaque authentication response data generated by Authentication Method indicated by the plugin name field.
}
if capabilities & CLIENT_CONNECT_WITH_DB {
string<NUL> database initial database for the connection. This string should be interpreted using the character set indicated by character set field.
}
if capabilities & CLIENT_PLUGIN_AUTH {
string<NUL> client_plugin_name the Authentication Method used by the client to generate auth-response value in this packet. This is an UTF-8 string.
}
if capabilities & CLIENT_CONNECT_ATTRS {
int<lenenc> length of all key-values affected rows
string<lenenc> key1 Name of the 1st client attribute
string<lenenc> value1 Value of the 1st client attribute
.. (if more data in length of all key-values, more keys and values parts)
}
if capabilities & CLIENT_ZSTD_COMPRESSION_ALGORITHM {
int<1> zstd_compression_level compression level for zstd compression algorithm
}

Example

On MySQL 5.5.8 with CLIENT_PROTOCOL_41 CLIENT_PLUGIN_AUTH, CLIENT_SECURE_CONNECTION (removed in 8.0), and CLIENT_CONNECT_WITH_DB set, it may look like:

54 00 00 01 8d a6 0f 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 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 00 assword.

Starting with MySQL 5.6.6 the client may send attributes if CLIENT_CONNECT_ATTRS is set:

b2 00 00 01 85 a2 1e 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 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._client_name
08 6c 69 62 6d 79 73 71 6c 04 5f 70 69 64 05 32 .libmysql._pid.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
Warning
Currently, multibyte character sets such as UCS2, UTF16 and UTF32 are not supported.
Note
If client wants to have a secure SSL connection and sets CLIENT_SSL flag it should first send the Protocol::SSLRequest: packet and only then, after establishing the secure connection, it should send the Protocol::HandshakeResponse: packet.