mysql一直copying to tmp table_mysql出现Copying to tmp table怎么处理

优化数据库是,出现这个 Copying to tmp table,如何处理# 在mysql里用输入这个查询会列出当前执行的费时的查询

show full processlist

今天在MYSQL中偶然发现查询命令中有很多语名处在Copying to tmp table状态,接口响应也变得很慢。因为业务需要这个SQL也确实比较复杂,同时因为有union操作,也使用到了临时表。

93cc1107295cb649ea1acd2d82f869ab.png

Copying to tmp table on disk The temporary result set was larger than tmp_table_size and the thread is now changing the in memory-based temporary table to a disk based one to save memory.

Copying to tmp table状态即表示如果查询超出了MYSQL中配置的tmp_table_size的限制,tmp_table_size配置是每个线程都要分配的大小。应用中实际起限制作用除了tmp_table_size配置外还有max_heap_table_size(会取两者中的最小值)。如果内存临时表超出了限制,MySQL就会自动地把它转化为基于磁盘的MyISAM表,并用配置中的tmpdir即/tmp来保存查询结果,这无疑会降低响应速度。

但是我的MYSQL本身的配置也不低:tmp_table_size已经配置为1G了.mysql> show variables like '%tmp%';+-------------------+------------+| Variable_name     | Value      |+-------------------+------------+| max_tmp_tables    | 32         || slave_load_tmpdir | /tmp       || tmp_table_size    | 1073741824 || tmpdir            | /tmp       |+-------------------+------------+mysql> show variables like  'max_heap_table_size';+---------------------+------------+| Variable_name       | Value      |+---------------------+------------+| max_heap_table_size | 1073741824 |+---------------------+------------+1 row in set (0.00 sec)

临时解决方案是:#附上动态改变配置tmp_table_size和max_heap_table_size的命令

set global tmp_table_size=1073741824;

set max_heap_table_size=1073741824;

长期解决方案:

建议一定要修改查询慢的sql语句

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值