Documentation Home
MySQL Internals Manual
Download this Manual
EPUB - 0.8Mb


MySQL Internals Manual  /  ...  /  A mysql Client Logs In

14.12.1 A mysql Client Logs In

Tip

All the examples here are captured with

$ ngrep -x -q -d lo0 '' 'port 3306'

Taking a look at the packet dump when a mysql-client logs in:

client -> server
  <connect>

The client initiates the communication by connecting to the server:

server -> client
  36 00 00 00 0a 35 2e 35    2e 32 2d 6d 32 00 03 00    6....5.5.2-m2...
  00 00 27 75 3e 6f 38 66    79 4e 00 ff f7 08 02 00    ..'u>o8fyN......
  00 00 00 00 00 00 00 00    00 00 00 00 00 57 4d 5d    .............WM]
  6a 7c 53 68 32 5c 59 2e    73 00                      j|Sh2\Y.s.

which responds with a handshake packet which contains the version, some flags and a password challenge.:

client -> server
  3a 00 00 01 05 a6 03 00    00 00 00 01 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 cb b5 ea 68 eb 6b    ....root.....h.k
  3b 03 cb ae fb 9b df 5a    cb 0f 6d b5 de fd          ;......Z..m...

The client answers with username, some flags and the response to the challenge.:

server -> client
  07 00 00 02 00 00 00 02    00 00 00                   ...........

As the client provided the right password and the flags are fine, the server responds with a OK_Packet. That closes auth-phase and switches to the command-phase:

client -> server
  21 00 00 00 03 73 65 6c    65 63 74 20 40 40 76 65    !....select @@ve
  72 73 69 6f 6e 5f 63 6f    6d 6d 65 6e 74 20 6c 69    rsion_comment li
  6d 69 74 20 31                                        mit 1

The mysql client first checks the version string of the server and sends a COM_QUERY packet.:

server -> client
  01 00 00 01 01 27 00 00    02 03 64 65 66 00 00 00    .....'....def...
  11 40 40 76 65 72 73 69    6f 6e 5f 63 6f 6d 6d 65    .@@version_comme
  6e 74 00 0c 08 00 1c 00    00 00 fd 00 00 1f 00 00    nt..............
  05 00 00 03 fe 00 00 02    00 1d 00 00 04 1c 4d 79    ..............My
  53 51 4c 20 43 6f 6d 6d    75 6e 69 74 79 20 53 65    SQL Community Se
  72 76 65 72 20 28 47 50    4c 29 05 00 00 05 fe 00    rver (GPL)......
  00 02 00                                              ...

The server responds with a resultset containing the version-string.:

client -> server
  0e 00 00 00 03 73 65 6c    65 63 74 20 55 53 45 52    .....select USER
  28 29                                                 ()

For the prompt (u ...) the mysql client also asks for the current username.:

server -> client
  01 00 00 01 01 1c 00 00    02 03 64 65 66 00 00 00    ..........def...
  06 55 53 45 52 28 29 00    0c 08 00 4d 00 00 00 fd    .USER()....M....
  01 00 1f 00 00 05 00 00    03 fe 00 00 02 00 0f 00    ................
  00 04 0e 72 6f 6f 74 40    6c 6f 63 61 6c 68 6f 73    ...root@localhos
  74 05 00 00 05 fe 00 00    02 00                      t.........

which is 'root@localhost' in this example.


User Comments
Sign Up Login You must be logged in to post a comment.