标签:ali 结束 connected setting call 简单 signed end 资料
在connection的生命里,会一直有一个user thread(以及user thread对应的THD)陪伴它。
来自Stackoverflow的一个回答:
A session is just a result of a successful connection.
Any MySQL client requires some connection settings to establish a connection,
and after the connection has been established,
it acquires a connection id (thread id) and some context which is called session.
来自官方团队的描述:
Connections correspond to Sessions in SQL standard terminology.
A client connects to the MySQL Server and stays connected until it does a disconnect.
user thread
;要么新建一个OS thread,要么重用 thread cache里的可用thread;handshake packet
,接收查询、返回结果等等;注意:THD 一直没查到是什么的简写。从查阅的资料看,THD应该也可以被认为是 Session
或者 connection的状态/上下文
。
user thread
会进入 command phase
;开始忙碌的一生。Client发送COM_QUIT
命令开始断开连接操作。
User Thread开始做清理工作:
thread cache
还有空位置: 把自己 放到 thread cache
里并标记为 suspended
状态;thread cache
没有空位置:结束线程。MySQL的连接信息,记录在information_schema
和performance_schema
数据库中。
desc information_schema.processlist;
+---------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------------+------+-----+---------+-------+
| ID | bigint(21) unsigned | NO | | | |
| USER | varchar(32) | NO | | | |
| HOST | varchar(64) | NO | | | |
| DB | varchar(64) | YES | | | |
| COMMAND | varchar(16) | NO | | | |
| TIME | int(7) | NO | | | |
| STATE | varchar(64) | YES | | | |
| INFO | varchar(65535) | YES | | | |
+---------+---------------------+------+-----+---------+-------+
desc performance_schema.hosts;
+---------------------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+------------+------+-----+---------+-------+
| HOST | char(60) | YES | UNI | NULL | |
| CURRENT_CONNECTIONS | bigint(20) | NO | | NULL | |
| TOTAL_CONNECTIONS | bigint(20) | NO | | NULL | |
+---------------------+------------+------+-----+---------+-------+
方法1:
show status where variable_name = ‘threads_connected‘;
方法2:
show processlist;
方法3:
select id,
user,
host,
db,
command,
time,
state,
info
from information_schema.processlist;
select * FROM performance_schema.hosts;
MySQL基础知识:MySQL Connection和Session
标签:ali 结束 connected setting call 简单 signed end 资料
原文地址:https://www.cnblogs.com/codesee/p/14540272.html