MySQL总是将简单的临时/内存表写入磁盘(tmp_table_size和max_heap_table_size都设置为8GB)

时间:2015-01-30 03:18:39

标签: mysql

我正在努力解决这个问题,并且无法弄清楚为什么会这样。

CREATE TABLE sitecache._test ENGINE=MEMORY SELECT * FROM website.gallery_likes WHERE 1=0;

每次执行此查询时,已创建的tmp磁盘表服务器变量会立即增加 5 。同样的事情发生在CREATE TEMPORARY TABLE ...上,也用于创建具有结构定义的表,而不是从另一个表复制结构。

website.gallery_likes 的结构:

CREATE TABLE gallery_likes (
  photoid mediumint(8) unsigned NOT NULL,
  userid int(10) unsigned NOT NULL,
  timestamp int(10) unsigned NOT NULL,
  KEY photoid (photoid,userid)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

正如你所看到的那样,没有TEXT和没有BLOB字段,它是一个相当简单的表。如果我然后将大量数据转储到该临时/内存表中,则需要几分钟才能完成,我可以看到mysqld如何将大量数据写入C:\ Windows \ Temp目录中的临时文件。

tmp_table_size max_heap_table_size 都设置为8GB(并通过SHOW VARIABLES确认)。

在具有64GB RAM的Windows Server 2012 R2 x64上运行MySQL 5.6.17 x64。

配置:

[client]
no-beep
port=3306

[mysql]
default-character-set=latin1

[mysqld_safe]
open-files-limit=16384

[mysqld]
log-bin="D:/MySQL Blackhole/master_replication.log"
sync_binlog=0
binlog-do-db=...
binlog-ignore-db=...
...edited...
binlog-format=STATEMENT
expire_logs_days=1
server-id=1
ft_min_word_len=3
innodb_ft_min_token_size=3
port=3306
datadir="D:/MySQL/data/"
character-set-server=latin1
default-storage-engine=MYISAM
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
log-output=NONE
general-log=0
general_log_file="MYSQL_SERVER.log"
slow-query-log=0
slow_query_log_file="MYSQL_SERVER-slow.log"
long_query_time=10
log-error="MYSQL_SERVER.err"
max_connections=1024
query_cache_size=0
table_open_cache=4096
tmp_table_size=8G
max_heap_table_size=8G
thread_cache_size=64
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=256M
key_buffer_size=8192M
read_buffer_size=2M
read_rnd_buffer_size=128M
sort_buffer_size=8M
innodb_flush_log_at_trx_commit=0
innodb_flush_log_at_timeout=1
innodb_log_buffer_size=32M
innodb_buffer_pool_size=32G
innodb_log_file_size=8G
innodb_thread_concurrency=0
innodb_autoextend_increment=64
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=0
innodb_open_files=4096
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=strict_crc32
innodb_adaptive_hash_index=ON
back_log=80
flush_time=0
join_buffer_size=8M
max_allowed_packet=16M
max_connect_errors=10
open_files_limit=16384
query_cache_type=0
table_definition_cache=2500

(故意query_cache_size=0default-storage-engine=MYISAM

我现在多次阅读文档,但我还没有看到为什么会发生这种情况的任何关联。该表非常简单,没有超过512字节的列。

1 个答案:

答案 0 :(得分:0)

好的,如果有人遇到类似的问题,谷歌会指示他们:
我并没有弄清楚原因,但有点弄明白是什么导致它, phpMyAdmin 是罪魁祸首。

直接在mysql命令行中发出相同的命令不会导致临时表写入磁盘 现在,我的开发机器上也有phpMyAdmin,这不是问题。但我在Apache中运行PHP作为模块,而在生产服务器上运行的是PHP,其中PHP作为FastCGI运行。因此,一些配置或限制必定导致了这一点,并不完全确定。