mysql握手连接协议
来源:互联网 发布:拷贝文件夹到mac 编辑:程序博客网 时间:2024/06/06 12:48
1,建立MySql连接
a) 服务端往客户端发送握手初始化包(Handshake Initialization Packet)
b) 客户端往服务端发送验证包(Client Authentication Packet)
c) 服务端往客户端发送成功包
2,校验方法
在 a) 服务端往客户端发送握手初始化包(Handshake Initialization Packet),会携带客户端应该使用的authentication method.
每个用户使用什么样的校验方法是确定的,在mysql.user表中:Method used for authentication is tied to the user account and stored in the plugin column of mysql.user table.
mysql> select * from mysql.user where user = 'vddl' limit 10 \G;*************************** 1. row *************************** Host: localhost User: vddl Password: *57B4F32D94FF1EC6EC480F8F437B795BEE4A994F Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: N Shutdown_priv: N Process_priv: N File_priv: N Grant_priv: N References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: N Super_priv: N Create_tmp_table_priv: N Lock_tables_priv: N Execute_priv: N Repl_slave_priv: N Repl_client_priv: N Create_view_priv: N Show_view_priv: N Create_routine_priv: N Alter_routine_priv: N Create_user_priv: N Event_priv: N Trigger_priv: YCreate_tablespace_priv: N ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 plugin: mysql_native_password authentication_string: password_expired: N
其中,plugin: mysql_native_password字段指定了应该使用什么校验方法。
抓包工具也可以看到
0000 02 00 00 00 45 00 00 86 59 22 40 00 40 06 00 00 ....E...Y"@.@...0010 7f 00 00 01 7f 00 00 01 0c ea f0 fe b7 3c 39 4c .............<9L0020 2e ac 31 1f 80 18 31 d7 fe 7a 00 00 01 01 08 0a ..1...1..z......0030 13 0f 4c 2f 13 0f 4c 2f 4e 00 00 00 0a 35 2e 36 ..L/..L/N....5.60040 2e 32 34 2d 6c 6f 67 00 03 00 00 00 2c 48 64 43 .24-log.....,HdC0050 5e 33 22 4d 00 ff f7 08 02 00 7f 80 15 00 00 00 ^3"M............0060 00 00 00 00 00 00 00 41 3a 42 7b 65 68 5d 75 57 .......A:B{eh]uW0070 32 34 4f 00 6d 79 73 71 6c 5f 6e 61 74 69 76 65 24O.mysql_native0080 5f 70 61 73 73 77 6f 72 64 00 _password.
最后,也会有mysql_native_password.
具体协议格式:
https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeV10
3,客户端上传用户名、密码、当前数据库
参考:http://www.jianshu.com/p/651fb39c0a51
4,超时时间
建立mysql连接时,有个超时时间的概念。
mysql> show variables like '%timeout%';+-----------------------------+----------+| Variable_name | Value |+-----------------------------+----------+| connect_timeout | 10 |
connect_time 表明mysql握手连接协议中,校验超时时间。默认是10秒;
通过telnet我们可以进行模拟:
首先我们使用telnet 127.0.0.1 3306命令进行建立tcp连接
yangyamin:~ yangyamin$ telnet 127.0.0.1 3306Trying 127.0.0.1...Connected to localhost.Escape character is '^]'.N5.6.24-loam!Y~/k�&o}I4d~m({Uwmysql_native_passwordConnection closed by foreign host.yangyamin:~ yangyamin$
客户端telnet不发送命令的话,我们发现连接会自动断开。
其中NO14标示的是mysql服务器的Handshake Initialization Packet。而NO18比NO17的时间延迟正好是10秒,即connect_time。
5,连接过程中的状态
mysql连接握手协议第二步骤:b) 客户端往服务端发送验证包(Client Authentication Packet)
在此之前,连接状态为 unauthenticated user。
mysql> show processlist;+----+----------------------+-----------------+------+---------+------+------------------+------------------+| Id | User | Host | db | Command | Time | State | Info |+----+----------------------+-----------------+------+---------+------+------------------+------------------+| 5 | root | localhost | NULL | Query | 0 | init | show processlist || 9 | unauthenticated user | localhost:65322 | NULL | Connect | NULL | Reading from net | NULL |+----+----------------------+-----------------+------+---------+------+------------------+------------------+2 rows in set (0.00 sec)
- mysql握手连接协议
- Websocket协议之握手连接
- TCP 协议的握手连接
- tcp协议的”三次握手“连接与“四次握手”断开
- TCP/IP协议三次握手建立连接
- 三次握手协议——TCP连接
- TCP协议之三次握手建立连接
- TCP协议建立连接的三次握手
- TCP3次握手连接协议和4次握手断开连接协议
- TCP3次握手连接协议和4次握手断开连接协议
- TCP3次握手连接协议和4次握手断开连接协议
- TCP3次握手连接协议和4次握手断开连接协议
- 【转】TCP3次握手连接协议和4次握手断开连接协议
- TCP3次握手连接协议和4次握手断开连接协议
- TCP3次握手连接协议和4次握手断开连接协议
- TCP3次握手连接协议和4次握手断开连接协议
- TCP3次握手连接协议和4次握手断开连接协议
- TCP3次握手连接协议和4次握手断开连接协议
- Postman
- android theme主题使用遇到的一个小问题
- post与get请求中文乱码问题
- javascript——BOM
- ThinkPHP 增删改查操作
- mysql握手连接协议
- ELK搭建(5.1版本)
- RxAndroid+Retrofit+GreenDao+MVP框架---通用基类封装(三)
- 瀑布模型开发与敏捷开发的对比
- 学习Pyqt5(一)
- MySql中的varchar类型
- django auto_now与auto_now_add的区别
- hdu2016校赛1002递增数 dfs搜索
- Zookeeper核心机制