【动手实验】MySQL 客户端 SocketTimeout 问题抓包分析
实验准备 服务端环境准备 服务器信息 阿里云 99 大洋白嫖机 1 2 [root@t01 ~]# cat /proc/version Linux version 5.10.134-18.al8.x86_64 (mockbuild@h87c01383.na61) (gcc (GCC) 10.2.1 20200825 (Alibaba 10.2.1-3.8 2.32), GNU ld version 2.35-12.3.al8) #1 SMP Fri Dec 13 16:56:53 CST 2024 安装 JDK, docker, tshark 1 yum install -y java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 podman-docker.noarch wireshark 启动 MySQL 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 [root@t01 ~]# docker run -it -d --net=host -e MYSQL_ROOT_PASSWORD=123 --name=mysql mysql:8.0.28 Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. 233c8ca518d0e8feef367995aee656fffb65b6a2f16a589d2e765f06dad96828 [root@t01 ~]# docker ps Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 233c8ca518d0 docker.io/library/mysql:8.0.28 mysqld 11 seconds ago Up 12 seconds mysql [root@t01 ~]# docker exec -it mysql sh Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. # mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.28 MySQL Community Server - GPL Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> \s -------------- mysql Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL) Connection id: 8 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 8.0.28 MySQL Community Server - GPL Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: latin1 Conn. characterset: latin1 UNIX socket: /var/run/mysqld/mysqld.sock Binary data as: Hexadecimal Uptime: 23 sec Threads: 2 Questions: 5 Slow queries: 0 Opens: 117 Flush tables: 3 Open tables: 36 Queries per second avg: 0.217 -------------- 初始化 MySQL 密码、数据库 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 CREATE DATABASE test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123'; CREATE USER 'test'@'%' IDENTIFIED BY '123'; GRANT ALL PRIVILEGES ON test.* TO test@'%'; FLUSH PRIVILEGES; # 创建表 create table t_user ( id bigint(20) unsigned not null auto_increment primary key comment 'primary key', name varchar(64) not null default '' comment 'user name', age tinyint unsigned not null default 0 comment '年龄', gender tinyint unsigned not null default 0 comment '性别, 0 男,1 女', create_at datetime(3) not null default current_timestamp(3) comment 'record create date', update_at datetime(3) not null default current_timestamp(3) on update current_timestamp(3) comment 'record update date' ) engine = innodb default charset = utf8mb4 collate = utf8mb4_unicode_ci comment '用户表'; # 插入数据 insert into t_user (id, name, age) values (1, "tom", 18); 执行查询 1 2 3 4 5 6 7 8 9 10 mysql> select sleep(10), id, name from t_user where id = 100; Empty set (0.00 sec) mysql> select sleep(10), id, name from t_user where id = 1; +-----------+----+------+ | sleep(10) | id | name | +-----------+----+------+ | 0 | 1 | tom | +-----------+----+------+ 1 row in set (10.00 sec) 能查到数据时,sleep 生效 数据不存在时,sleep 不生效 服务端抓包命令 ...