每个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之判断和循环

    计算机之所以能做很多自动化的任务,因为它可以自己做条件判断.比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,可以用if语句实现: age = : print ('your age i ...

  2. ZooKeeper--动物管理员

    复杂的软件集群系统从来绕不开高可用.负载均衡等问题,大数据系统更是如此. 高可用:计算机系统的可用性定义为系统保持正常运行时间的百分比,具体手段有自动检测,自动切换,自动恢复等. 负载均衡:主要解决单 ...

  3. Delphi 画刷与作图区域

    樊伟胜

  4. 3.NumPy - 数组属性

    1.ndarray.shape 这一数组属性返回一个包含数组维度的元组,它也可以用于调整数组大小 # -*- coding: utf-8 -*- import numpy as np a = np.a ...

  5. 二进制;16进制; Byte , Python的bytes类; Base64数据编码; Bae64模块;

    参考:中文维基 二进制 位操作(wiki) Byte字节 互联网数据处理:Base64数据编码 Python的模块Base64 16进制简介 python: bytes对象 字符集介绍:ascii 二 ...

  6. mysql router使用配置

    mysql router使用配置 参考资料: https://www.jianshu.com/p/7fc8d77bea59 一.架构图 介绍: MySQL Router是处于应用client和dbse ...

  7. 【原】spring+mybatis下sqlSession.delete和insert返回值-2147482646问题

    这是由于spring-beans.xml中的batch批处理配置所导致的,注释掉BATCH配置的代码就可以返回1了: <bean id="sqlSessionFactory" ...

  8. 【原】eclipse save action设置文件保存时自动格式化

    学了一段java了,发现其实eclipse有很多实用小功能,能够让你编码的时候快捷方便,如果你苦于一些你常用到的功能无法自动实现,那么你可以上网查一下,就会发现其实eclipse已经给你提供了便捷之路 ...

  9. Codeforces 839E Mother of Dragons

    题 OvO http://codeforces.com/contest/839/problem/E (Codeforces Round #428 (Div. 2) - E) 解 首先,k肯定是要平均分 ...

  10. if语句分析

    1.if语句的反汇编判断 if语句反汇编后的标志:     执行各类影响标志位的指令             jxx xxxx 如果遇到上面的指令,则很可能是if语句:   例如:     1.案例一 ...