Mysql里的ibtmp1文件太大,导致磁盘空间被占满

目录

一、查看磁盘的时候发现磁盘空间100%

二、 排查的时候:查看是什么文件占用的时候,发现是数据库临时表空间增长的

三、为了避免以后再次出现ibtmp1文件暴涨,限制其大小,需在配置文件加入

四、重启Mysql实例(重启后ibtmp1文件会自动清理)

五 、重启后,验证配置是否生效

总结:

一、查看磁盘的时候发现磁盘空间100%

 

二、 排查的时候:查看是什么文件占用的时候,发现是数据库临时表空间增长的

 

 

备注:默认配置为ibtmp1:12M:autoextend,也就是说在默认情况下支持大文件的系统这个文件大小是可以无限增长的。 

mysql> show variables like 'innodb_temp_data_file_path';
+----------------------------+-----------------------+
| Variable_name              | Value                 |
+----------------------------+-----------------------+
| innodb_temp_data_file_path | ibtmp1:12M:autoextend |
+----------------------------+-----------------------+
1 row in set (0.01 sec)
 

为了避免以后再次出现ibtmp1文件暴涨,限制其大小,需在配置文件加入

vim /etc/my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
#

port=31306
datadir=/datah/data/mysqldata/mysql
socket=/var/lib/mysql/mysql.sock

symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

character-set-server=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
init_connect='SET NAMES utf8'
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
wait_timeout=20000
max_user_connections=5000
max_allowed_packet=128M
thread_stack=262144

#为了避免以后再次出现ibtmp1文件暴涨,限制其大小
innodb_temp_data_file_path=ibtmp1:12M:autoextend:max:20G

#skip-grant-tables
 

四、重启Mysql实例(重启后ibtmp1文件会自动清理)

systemctl restart mysqld

五 、重启后,验证配置是否生效

 mysql> show variables like 'innodb_temp_data_file_path';
+----------------------------+-------------------------------+
| Variable_name              | Value                         |
+----------------------------+-------------------------------+
| innodb_temp_data_file_path | ibtmp1:12M:autoextend:max:20G |
+----------------------------+-------------------------------+
1 row in set (0.01 sec)

总结:

可能导致ibtmp1文件暴涨的情况:

  1. 用到临时表,当EXPLAIN 查看执行计划结果的 Extra 列中,如果包含 Using Temporary就表示会用到临时表。
  2. GROUP BY无索引字段或GROUP BY + ORDER BY的子句字段不一样时。
  3. order by与distinct共用,其中distinct与order by里的字段不一致(主键字段除外)。
  4. insert into table1 select xxx from table2。

解决办法:

  1. 限制 ibtmp1 文件大小:innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:20G
  2. 优化 SQL,避免使用临时表。
  3. 重启 mysql 实例释放 ibtmp1 文件

  • 27
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

求知若渴,虚心若愚。

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值