每个MySQL连接,都有一个连接ID,可以通过 connection_id()查看。
连接id也可以通过以下方式查看:
- show processlist中id列
- information_schema.processlist的id列
- performance_schema.threads的processlist_id 列
下面通过具体命令查看连接id。
查看连接id:
mysql> select connection_id();
+-----------------+
| connection_id() |
+-----------------+
| 15 |
+-----------------+
1 row in set (0.00 sec)
查看show processlist:
mysql> show processlist;
+----+------+-----------------+------+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------------+------+---------+------+----------+------------------+
| 3 | root | localhost:60989 | cmdb | Sleep | 318 | | NULL |
| 4 | root | localhost:60990 | cmdb | Sleep | 318 | | NULL |
| 15 | root | localhost | NULL | Query | 0 | starting | show processlist |
+----+------+-----------------+------+---------+------+----------+------------------+
3 rows in set (0.00 sec)
查看数据表information_schema.processlist:
mysql> select * from information_schema.processlist;
+----+------+-----------------+------+---------+------+-----------+-----------------------------------------------+
| ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO |
+----+------+-----------------+------+---------+------+-----------+-----------------------------------------------+
| 3 | root | localhost:60989 | cmdb | Sleep | 157 | | NULL |
| 15 | root | localhost | NULL | Query | 0 | executing | select * from INFORMATION_SCHEMA.PROCESSLIST |
| 4 | root | localhost:60990 | cmdb | Sleep | 157 | | NULL |
+----+------+-----------------+------+---------+------+-----------+-----------------------------------------------+
3 rows in set (0.00 sec)
查看数据表performance_schema.threads:
mysql> select thread_id, name, processlist_id from performance_schema.threads;
+-----------+----------------------------------------+----------------+
| thread_id | name | processlist_id |
+-----------+----------------------------------------+----------------+
| 1 | thread/sql/main | NULL |
| 2 | thread/sql/thread_timer_notifier | NULL |
| 3 | thread/innodb/io_ibuf_thread | NULL |
| 4 | thread/innodb/io_log_thread | NULL |
| 5 | thread/innodb/io_read_thread | NULL |
| 6 | thread/innodb/io_read_thread | NULL |
| 7 | thread/innodb/io_read_thread | NULL |
| 8 | thread/innodb/io_read_thread | NULL |
| 9 | thread/innodb/io_write_thread | NULL |
| 10 | thread/innodb/io_write_thread | NULL |
| 11 | thread/innodb/io_write_thread | NULL |
| 12 | thread/innodb/io_write_thread | NULL |
| 13 | thread/innodb/page_cleaner_thread | NULL |
| 16 | thread/innodb/srv_lock_timeout_thread | NULL |
| 15 | thread/innodb/srv_error_monitor_thread | NULL |
| 17 | thread/innodb/srv_monitor_thread | NULL |
| 18 | thread/innodb/srv_master_thread | NULL |
| 19 | thread/innodb/srv_worker_thread | NULL |
| 20 | thread/innodb/srv_worker_thread | NULL |
| 21 | thread/innodb/srv_purge_thread | NULL |
| 22 | thread/innodb/srv_worker_thread | NULL |
| 23 | thread/innodb/buf_dump_thread | NULL |
| 24 | thread/innodb/dict_stats_thread | NULL |
| 25 | thread/sql/signal_handler | NULL |
| 26 | thread/sql/compress_gtid_table | 1 |
| 28 | thread/sql/one_connection | 3 |
| 29 | thread/sql/one_connection | 4 |
| 40 | thread/sql/one_connection | 15 |
+-----------+----------------------------------------+----------------+
28 rows in set (0.00 sec)
参考
https://dev.mysql.com/doc/refman/5.7/en/information-functions.html
Just try, don't shy.
分类:
MySQL
标签:
mysql
, connection_id
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现