首页 > 数据库 >MySQL 术语 : processes, threads, connections

MySQL 术语 : processes, threads, connections

时间:2024-03-19 17:14:31浏览次数:27  
标签:processes show 连接 connections 线程 processlist threads id schema

MySQL 是单进程、多线程架构。通常说的连接(connections)是指TCP/IP连接。每个连接对应一个专用的线程。
但是这些线程有时候被叫做进程,有时候被当作连接。这也是为什么processes, threads, connections三者会让人产生混淆的原因。

MySQL 确实是一个单进程服务器。它是多线程的,因为服务器上有许多明显的和不太明显的线程。这些线程包括 InnoDB I/O 线程、DELAYED INSERT线程等。当然还有连接线程。稍后会详细介绍。

在较旧的 Linux 版本或 glibc-static 版本上,人们可能会把 MySQL 看成是一个多进程服务器。其实不然:这只是因为线程被映射到了操作系统进程。mysqld 是单个进程。

因此,每个新连接都有自己的线程。假设没有使用线程池,那么每个新连接都会创建一个新线程,而断开连接则会导致该线程被销毁。因此,连接和活动线程之间存在 1-1 映射关系。
但是,线程池意味着可能存在与任何连接都不相关的线程。

这里就是术语容易混淆的地方。当你想查看服务器上正在执行的程序时,可以发出 SHOW PROCESSLIST(显示进程列表):

>show processlist;
+----------+-----------------+---------------------+-----------+------------------+----------+-----------------------------------------------------------------+------------------+
| Id       | User            | Host                | db        | Command          | Time     | State                                                           | Info             |
+----------+-----------------+---------------------+-----------+------------------+----------+-----------------------------------------------------------------+------------------+
|        5 | event_scheduler | localhost           | NULL      | Daemon           | 20196680 | Waiting on empty queue                                          | NULL             |
| 48151579 | root            | localhost           | NULL      | Query            |        0 | init                                                            | show processlist |
...
+----------+-----------------+---------------------+-----------+------------------+----------+-----------------------------------------------------------------+------------------+

这里也许叫做"show threadlist"可能更合适!!!毕竟输出显示的不是真的进程。

这里 id=48151579 就是我当前创建的连接:

>SELECT CONNECTION_ID();
+-----------------+
| CONNECTION_ID() |
+-----------------+
|        48151579 |
+-----------------+

查看当前有多少活跃的进程或连接,可以通过Threads_running状态变量来查看:

>SHOW GLOBAL STATUS LIKE 'Threads_running';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| Threads_running | 5     |
+-----------------+-------+

在MySQL 8.0中,information_schema.processlist表已经过期,在以后的版本中会被移除。因此,使用information_schema.processlist表的show processlist也过期了。现在推荐使用performance_schema.processlist表。

information_schema.processlist.id 等价于 show processlist中显示的id,等价于performance_schema.threads.processlist_id。

>select thread_id,processlist_id,thread_os_id from performance_schema.threads;
+-----------+----------------+--------------+
| thread_id | processlist_id | thread_os_id |
+-----------+----------------+--------------+
|         1 |           NULL |         9240 |
|         3 |           NULL |         9248 |
|  48170655 |       48170192 |        34483 |
...

这里的thread_os_id是mysql内部线程对应的系统线程id。可以通过操作系统命令ps查看:ps -Lef|grep <thread_os_id>
对于前台线程(与用户连接有关),processlist_id表示连接标识符,等价于information_schema.processlist.id,也等价于show processlist中显示的id。
对于后台线程(与用户连接无关),processlist_id是null。

写到这里,看起来还是有点乱。

标签:processes,show,连接,connections,线程,processlist,threads,id,schema
From: https://www.cnblogs.com/abclife/p/18079869

相关文章

  • SharePoint Online Viva Connections 添加到Teams
    前言我们新建了VivaConnections,然后如何让大家知道呢?Teams入口是一个非常好的方法。正文1.我们选择安装VivaConnections到Teams,如下图:2.这样会弹出安装的步骤,如下图:3.进入Teams管理中心,找到Teamsapps-Setuppolicies,如下图:4.添加一个新......
  • SharePoint Online 添加Viva Connections Dashboard报错
    前言上一篇博客为大家介绍了如何新建VivaConnectionsexperience,不过,在添加Dashboard的时候碰到了问题,这是因为默认不会新建Dashboard,我们需要手动创建。正文1.错误描述和错误截图,如下图:Can'tgetthisDashboardURL.Itmaynotbesetupyet,oritmay......
  • 如何新建SharePoint Online Viva Connections experiences
    前言Viva也是近些年来出现的一个新词汇,我们可以在Microsoft365中启用,我们今天简单介绍下。正文1.访问Microsoft365首页,找到Admin点击并进入,如下图:2.在左侧导航里找到设置,设置里有Viva,点击进入,如下图:3.找到VivaConnections,点击进入,如下图:4......
  • Understanding the linux kernel Chapter3 Processes
    ProcessDescriptorHowProcessesAreOrganizedtheprocessinstate:TASK_RUNNINGorganizedinrunqueuelistgroupTASK_STROPPED\EXIT_ZOMBIE\EXIT_DEADThereisnoneedtogroupprocessesinanyofthesethreestates,becausestopped,zombie,andd......
  • linux修改max user processes limits
    突破ulimit限制修改普通用户单个用户可同时运行的最大进程数(默认为4096)[root@xxxdevops]#cat/etc/security/limits.d/20-nproc.conf#Defaultlimitfornumberofuser'sprocessestoprevent#accidentalforkbombs.#Seerhbz#432903forreasoning.*......
  • jmeter安装成功后打不开,提示:Cause: CannotResolveClassException: com.blazemeter.jme
    下载安装Jmeter,环境变量也配置完成了,打开Jmeter脚本报错,提示:Cause:CannotResolveClassException:com.blazemeter.jmeter.threads.concurrency.ConcurrencyThreadGroup解决办法:1.可以试着下载安装Jmeter插件管理器,https://jmeter-plugins.org/install/Install/ 2.把步骤1中......
  • postgresql数据库报“connections on Unix domain socket "/tmp/.s.PGSQL.5432"?”
    使用postgresql数据库的时候经常遇到的问题:[postgres@test~]$psqlpsql:couldnotconnecttoserver:Nosuchfileordirectory Istheserverrunninglocallyandaccepting connectionsonUnixdomainsocket"/tmp/.s.PGSQL.5432"?现象如上,但是数据库是启动状态,将......
  • From Bench to Bioreactor: Scaling Up Bioprocesses for Commercial Success
    1.背景介绍Bioprocessesarefundamentaltomanyindustries,includingpharmaceuticals,foodandbeverage,andbioenergy.Astheseindustriesgrow,theneedtoscaleupbioprocessesbecomesincreasinglyimportant.However,scalingupbioprocessesisnotatrivi......
  • linux -bash: fork: retry: No child processes 解决
    Text.Text.Text.Text.[ubuntu@iZj6cc8f0831kkdffvlhjhZtools]$date-bash:fork:retry:Nochildprocesses-bash:fork:retry:Nochildprocesses-bash:fork:retry:NochildprocessesFriDec2209:56:49CST2023corefilesize(blocks,-c)......
  • Mysql报错:too many connections原因及解决方法
    原因是mysql连接数过多解决方案一:1、linux登录mysql:mysql-uroot-p;2、查看mysql允许的最大连接数showvariableslike'%max_connections%';3、查看这次mysql服务启动到现在,同一时刻最多mysql有多少连接showstatuslike'Max_used_connections';4、修改mysql最大连......