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:" ...
随机推荐
- [css知识体系]flexbox模型
背景 flexbox 模型的产生主要是为给布局.对齐和容器内的空间分配提供一个更有效的方法,即使尺寸未知或是动态改变的(flex,收缩,弹性 就是为此命名). flex布局使得容器能够改变子元素的宽高 ...
- 转:KVM 虚拟机的克隆
KVM 虚拟机的克隆 首先把需要克隆的源虚拟机先关闭,然后使用以下命令来进行克隆,注意我这里使用的是相对路径. virsh shutdown VM02 virt-clone -o VM02 -n ...
- 三、SpringBoot项目探究
1.pom文件 父项目 <parent> <groupId>org.springframework.boot</groupId> <artifactId> ...
- Table 'jiang.hibernate_sequence' doesn't exist
spring+struts2+hibernate 运行报错 Table 'jiang.hibernate_sequence' doesn't exist 解决方法 一. 在hibernate.cfg. ...
- postgresql中rank() over, dense_rank(), row_number() 的用法和区别
- jdbc blob插入及查询操作
首先建一张表 create table picture( picId ) primary key not null, picName ) not null, picfile image null ) ...
- Delphi直接读取XmL
有时,只需要用XML作一些小的应用,比如只是简单地保存日志或者一些配置,这时我们只需要直接读写XML就好,效率第一. Delphi盒子有一个直接读写XML文件 (例子和代码),其核心函数为下面两个函数 ...
- iOS 完全复制UIView
如果要完全复制一个UIView和对象的时候可以使用对象序列化方法 // Duplicate UIView - (UIView*)duplicate:(UIView*)view { NSData * t ...
- 如何将当前平台升级到SonarQube7.9?[最新]
整体思路 准备测试数据(实际环境可跳过此步骤) 数据库迁移(从版本7.9开始,SonarQube将不再支持MySQL,Mysql-->PG) Sonar版本升级(6.7.7 -> 7.9. ...
- Blazor 组件库 Blazui 开发第一弹【安装入门】
标签: Blazor Blazui文档 Blazui 传送门 Blazor 组件库 Blazui 开发第一弹[安装入门]https://www.cnblogs.com/wzxinchen/p/1209 ...