每个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

https://dev.mysql.com/doc/refman/5.7/en/threads-table.html

如何查看MySQL connection id连接id的更多相关文章

  1. 查看MySQL数据的连接

      show processlist;   select host from information_schema.processlist;   查看那台机器及连接数 select host, cur ...

  2. 查看mysql服务器连接

    查看服务器连接,排查连接过多,查看连接状态时特别有用! 命令: show full processlist 作用: 显示当前运行的线程以及状态,也可以根据该命令来查看服务器状态. Id: 连接Id.U ...

  3. 查看MySQL 连接信息--连接空闲时间及正在执行的SQL

    MySQL 客户端与MySQL server建立连接后,就可以执行SQL语句了. 如何查看一个连接上是否正在执行SQL语句,或者连接是否处于空闲呢? 下面我们做下测试. 1.查看连接的空闲时间 首先看 ...

  4. MYSQL获取自增ID的四种方法

    MYSQL获取自增ID的四种方法 1. select max(id) from tablename 2.SELECT LAST_INSERT_ID() 函数 LAST_INSERT_ID 是与tabl ...

  5. [转]MySQL 5.6 全局事务 ID(GTID)实现原理(二)

    原文连接:http://qing.blog.sina.com.cn/1757661907/68c3cad333002qsk.html 原文作者:淘长源 转载注明以上信息 前文 MySQL 5.6 全局 ...

  6. [转]MySQL 5.6 全局事务 ID(GTID)实现原理(一)

    原文作者:淘长源 原文连接:http://qing.blog.sina.com.cn/1757661907/68c3cad333002qhe.html 转载注明以上信息   MySQL 5.6 的新特 ...

  7. DBS-MySQL:MYSQL获取自增ID的四种方法

    ylbtech-DBS-MySQL:MYSQL获取自增ID的四种方法 1.返回顶部 1. 1. select max(id) from tablename 2.SELECT LAST_INSERT_I ...

  8. SignalR系列续集[系列6:使用自己的连接ID]

    目录 SignalR系列目录 前言 老规矩,前言~,在此先道个歉,之前的1-5对很多细节问题都讲的不是很详细,也有很多人在QQ或者博客问我一些问题 所以,特开了这个续集.. - -, 讲一些大家在开发 ...

  9. mysql 数据库自增id 的总结

    有一个表StuInfo,里面只有两列 StuID,StuName其中StuID是int型,主键,自增列.现在我要插入数据,让他自动的向上增长,insert into StuInfo(StuID,Stu ...

随机推荐

  1. 通俗讲解python__new__()方法

    目录 通俗讲解python__new__()方法 引子: 小结: 通俗讲解python__new__()方法 转载于别人的博客https://blog.csdn.net/sj2050/article/ ...

  2. 【5】Zookeeper的ZAB协议

    一.ZAB协议(原子消息广播协议)   ZAB(Zookeeper Atomic Broadcast)协议是Zookeeper用来保证其数据一致性的核心算法,是一种支持崩溃恢复的原子广播协议.基于此协 ...

  3. php使用rdkafka进行消费

    如仅作为消费者或生产者,直接使用下面消费者或生产者的代码,并安装扩展即可. PHP要安装rdkafka扩展,而rdkafka又依赖librdkafka,因此你需要安装rdkafka和librdkafk ...

  4. 2、screen工具

    1.背景 系统管理员经常需要SSH 或者telent 远程登录到Linux 服务器,经常运行一些需要很长时间才能完成的任务,比如系统备份.ftp 传输等等.通常情况下我们都是为每一个这样的任务开一个远 ...

  5. 05.Zabbix自动化监控

    1.Zabbix自动发现(被动) 网络发现官方手册 网络发现由两个阶段组成:发现discovery和动作actions 1.单击配置->自动发现->启动默认的Local network 2 ...

  6. asyncio:python3未来并发编程主流、充满野心的模块

    介绍 asyncio是Python在3.5中正式引入的标准库,这是Python未来的并发编程的主流,非常重要的一个模块.有一个web框架叫sanic,就是基于asyncio,语法和flask类似,使用 ...

  7. STM32输出比较模式

    搜索好久,各种文章良莠不齐,转载以下几篇 http://www.eeworld.com.cn/mcu/article_2016101130334.html(输出比较冻结模式) http://www.e ...

  8. sum(n,m)的解法

    给出两个整数n和m,你应该计算从n到m的所有整数的和.换句话说,你应该计算: SUM(n,m)= n +(n + 1)+(n + 2)+ ... +(m-1)+ m 方法1. 方法2.

  9. 微信退款SpringBoot读取resource下的证书

    微信支付退款接口,需要证书双向验证,测试的时候证书暂时放在resource下,上图 起初MyConfig中我是这样,在本机IDE中运行没有问题 但到Linux服务器的docker中运行就IO异常了,查 ...

  10. 初始Ajax学习笔记

    前端: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <!--引入 ...