mysql 100%占用的解决
早上客户反应,其网站无法访问,无限转圈
上服务器,查看磁盘空间df -h,内存使用率free -m,网络流量iftop均正常
然后使用top查看时,发现mysql的cpu使用率上升到200%。
解决过程回放
进入mysql
查看正在执行的sql
mysql> use information_schema;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from PROCESSLIST where info is not null;
+-----+------+-----------+--------------------+---------+------+-----------+--------------------------------------------------+
| ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO |
+-----+------+-----------+--------------------+---------+------+-----------+--------------------------------------------------+
| 291 | root | localhost | information_schema | Query | 0 | executing | select * from PROCESSLIST where info is not null |
+-----+------+-----------+--------------------+---------+------+-----------+--------------------------------------------------+
1 row in set (0.00 sec)
mysql>
并没有发现有任何的异样,没有出现锁表状况
然后查看tmp_table_size的大小
mysql> show variables like '%table_size%';
+---------------------+-----------+
| Variable_name | Value |
+---------------------+-----------+
| max_heap_table_size | 16777216 |
| tmp_table_size | 16777216 |
+---------------------+-----------+
2 rows in set (0.00 sec)
确认两个值大小均为16M(安装的是mariadb 5.5)
查看free -m还有4G大小的内存,此处显得过小,将其一个值提升到500M,一个值提升至200M
[root@iZbp16s0cap5fnfk6bjvw1Z ~]# grep -v ^# /etc/my.cnf | grep -v ^$
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
tmp_table_size=200M
max_heap_table_size=500M
然后重启mysql
发现top的中mysql的cpu占用率使用已经大大下降,已经恢复至20%左右
事后总结
mysql cpu占用率很高,很有可能是因为查询时死表,或者说大量多表查询,导致cpu飚高。
另外也有可能是因为tmp_table_size过大,超出了mysql的内存大小使用设定,mysql会将一些table写入到磁盘中,这样也会大大引起cpu的使用率增大
在select * from PROCESSLIST where info is not null 中没有发现异样时,即可以推断另外一种的可能。
在mysql的官方文档中是这样写的
Storage Engines Used for Temporary Tables
An internal temporary table can be held in memory and processed by the MEMORY storage engine, or stored on disk and processed by the MyISAM storage engine.
If an internal temporary table is created as an in-memory table but becomes too large, MySQL automatically converts it to an on-disk table. The maximum size for in-memory temporary tables is determined from whichever of the values of tmp_table_size and max_heap_table_size is smaller. This differs from MEMORY tables explicitly created with CREATE TABLE: For such tables, only the max_heap_table_size system variable determines how large the table is permitted to grow and there is no conversion to on-disk format.
翻译过来的大意是,当tmp_table变得越来越大的时候,msql tmp_table使用内存最大值为tmp_table_size与max_heap_table_size两者中较小的值。
而最后一句话特别的重要,当create table的时候(mysql临时表使用内存肯定会增加),max_heap_table_size才是决定临时表能创建多少的值。
所以一般max_heap_table_size要大于tmp_table_size
mysql> show global status like "%created_tmp%";
+-------------------------+-------+
| Variable_name | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 1654 |
| Created_tmp_files | 6 |
| Created_tmp_tables | 1791 |
+-------------------------+-------+
3 rows in set (0.00 sec)
查看临时tables的实时数量
每次创建临时表,Created_tmp_tables增加,如果临时表大小超过tmp_table_size,则是在磁盘上创建临时表,但是其大小不能超过max_heap_table_size
mysql 100%占用的解决的更多相关文章
- mysql cpu 100% 满 优化方案 解决MySQL CPU占用100%的经验总结
下面是一些经验 供参考 解决MySQL CPU占用100%的经验总结 - karl_han的专栏 - CSDN博客 https://blog.csdn.net/karl_han/article/det ...
- 解决 MYSQL CPU 占用 100% 的经验总结
朋友主机(Windows 2003 + IIS + PHP + MYSQL )近来 MySQL 服务进程 (mysqld-nt.exe) CPU 占用率总为 100% 高居不下.此主机有10个左右的 ...
- Win10安装后必做的优化,解决磁盘100%占用
Win10安装后必做的优化,解决磁盘100%占用 01关闭家庭组 控制面板–管理工具–服务– HomeGroup Listener和HomeGroup Provider禁用. 02关闭磁盘碎片整理.自 ...
- paip.mysql备份慢的解决
paip.mysql备份慢的解决.txt 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/att ...
- Atitit.软件GUIbutton与仪表盘--db数据库区--导入mysql sql错误的解决之道
Atitit.软件GUIbutton与仪表盘--db数据库区--导入mysql sql错误的解决之道 Keyword::截取文本文件后部分 查看提示max_allowed_packet限制 Targe ...
- Mysql CPU占用高的问题解决方法小结
通过以前对mysql的操作经验,先将mysql的配置问题排除了,查看msyql是否运行正常,通过查看mysql data目录里面的*.err文件(将扩展名改为.txt)记事本查看即可.如果过大不建议用 ...
- Atitit.软件GUI按钮与仪表盘--db数据库区--导入mysql sql错误的解决之道
Atitit.软件GUI按钮与仪表盘--db数据库区--导入mysql sql错误的解决之道 Keyword::截取文本文件后部分 查看提示max_allowed_packet限制 Target Se ...
- MYSQL转换编码的解决方法
MYSQL转换编码的解决方法 一.在utf8的mysql下 得到中文‘游客’的gbk下的16进制编码 mysql> SELECT hex(CONVERT( '游客' USING gbk )); ...
- 设置height:100%无效的解决方法
设置height:100%无效的解决方法 刚接触网页排版的新手,常出现这种情况:设置table和div的高height="100%"无效,使用CSS来设置height:" ...
随机推荐
- 第10篇用 ConfigMap 管理配置
一.ConfigMap介绍管理配置: ConfigMap介绍 Secret 可以为 Pod 提供密码.Token.私钥等敏感数据:对于一些非敏感数据,比如应用的配置信息,则可以用 Config ...
- 转帖 移动端h5页面不同尺寸屏幕适配兼容方法
1. viewport属性及html页面结构 <meta name="viewport" content="width=device-width,initial ...
- PHPCMS如何修改网站名称,网站关键词,网站描述
首先需要登录网站后台,填写管理员用户名密码之后,点击登 点击phpcms后台顶部的"设置"按钮,如下图所示. 然后点击"相关设置"下的"站点管理&qu ...
- GPIO软件模拟IIC时序
一.MPU6050中的IIC时序 1.1 START和STOP SDA和SCL在高电平时,SDA拉低表示START.SCL拉低,表示可以传输数据. SDA和SCL在低电平时,SDA拉高表示STOP. ...
- CodeForces 731D (差分+线段扫描)
Description Archeologists have found a secret pass in the dungeon of one of the pyramids of Cyclelan ...
- React的contextType的使用方法简介
上一篇介绍了Context的使用方法.但是Context会让组件变得不纯粹,因为依赖了全局变量.所以这决定了Context一般不会大规模的使用.所以一般在一个组件中使用一个Context就好. 由于C ...
- 微信公众号ios10.1 版本白屏问题
真机调试IOS 10.1.x的版本不支持fetch 所以一直loading显示白屏. 其他设备都没问题. 所以用主要属性window.fetch用来判断是否支持fetch 属性 import { ba ...
- css 布局(圣杯、双飞翼)
一. 圣杯布局. 左右固宽,中间自适应 三列布局,中间宽度自适应,两边定宽: 中间部分要在浏览器中优先展示渲染: 具体步骤:1.设置基本样式2.圣杯布局是一种相对布局,首先设置父元素container ...
- MySql中4种批量更新的方法update table2,table1,批量更新用insert into ...on duplicate key update, 慎用replace into.
mysql 批量更新记录 MySql中4种批量更新的方法最近在完成MySql项目集成的情况下,需要增加批量更新的功能,根据网上的资料整理了一下,很好用,都测试过,可以直接使用. mysql 批量更新共 ...
- Losing session data in ASP.NET
Losing session data in ASP.NET By default Response.Redirect terminates thread execution and there mi ...