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:" ...
随机推荐
- SVN连接不上仓库,问题之一
如果之前用过SVN,在新的地址上用,发现一直连不上,报错.有可能是因为默认使用了之前的地址,所以没弹出输账号和密码的弹框. 解决方法就是:把之前的链接地址全部清除掉. 右键找到SVN里面的 Sett ...
- Jmeter 将正则表达式提取的参数传给全局(跨线程组使用变量)
一.使用正则表达式提取sessionId 1.在测试计划(跨线程组使用变量)--> 线程组(登录)--> 添加HTTP请求(登录接口) (1)创建测试计划: 勾选独立运行每个线程组(例如在 ...
- 使用KEIL C51实现的简单合作式多任务操作系统内核(单片机实现版本)
基于网上网友的代码,自己在单片机上实现, 特此记录分享之. 基于https://blog.csdn.net/yyx112358/article/details/78877523 //使用KEIL C5 ...
- python读取配置文件(ini、yaml、xml)
python读取配置文件(ini.yaml.xml)
- ceph cache pool配置
https://my.oschina.net/hanhanztj/blog/515410 0.引入 本文介绍如何配置cache pool tiering. cache pool的作用是提供可扩展的ca ...
- CSS分组和嵌套选择器
CSS 分组 和 嵌套 选择器 分组选择器 在样式表中有很多具有相同样式的元素.直线模组哪家好 h1 { color:green; } h2 { color:green; } p { ...
- FZU 2150 Fire Game (高姿势bfs--两个起点)
Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows ...
- centos7 安装PHP5.3 报错undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3'
系统:centos 7 原有PHP版本:5.6.27,5.4.45 试着安装nginx+多php版本,首先安装了5.6和5.4的版本,一帆风顺,但是在安装5.3.29版本时,出现问题了,configu ...
- POJ 1151 线段树+扫描线(计算矩形面积并)
前一篇博客有了讲解就不再叙述了 #include<cstdio> #include<cstring> #include<cmath> #include<ios ...
- LiveTelecast直播平台技术图谱skill-map
#直播平台技术图谱 ----##直播 ----###采集- **iOS** * HTTP Live Streaming * DirectShow- **Android** * setPreviewCa ...