簡體   English   中英

創建大型MySQL索引(1B行)失敗,並顯示“查詢期間與MySQL服務器的連接丟失”

[英]Creating a large MySQL index (1B rows) fails with “Lost connection to MySQL server during query”

我試圖在一個相當大的MySQL表(超過10億行,144GB)上創建一個復合索引。

ALTER TABLE table_name ADD INDEX id_date ( id, `date` );

我讓它整夜運行了好幾次,但是它始終失敗,並顯示以下消息(錯誤日志中沒有其他內容。)我不能確定查詢運行了多長時間,但可能要花大約八個小時。

ERROR 2013 (HY000) at line 3: Lost connection to MySQL server during query

我用SET expand_fast_index_creation=ON;嘗試過SET expand_fast_index_creation=ON; 但這似乎只會使其失效更快(也許一個小時)。

該服務器在Hetzner的專用Ubuntu盒子上運行,帶有32G RAM,4GB交換空間和8個內核。 大量可用磁盤空間(1TB磁盤)。

Server version: 5.6.13-rc61.0-log Percona Server (GPL), Release 61.0

這是my.cnf文件,主要是反復試驗的結果:

[mysqld]
# General
binlog_cache_size = 8M
binlog_format = row
character-set-server = utf8
connect_timeout = 10
datadir = /var/lib/mysql/data
delay_key_write = OFF
expire_logs_days = 10
join_buffer_size = 8M
log-bin=/var/lib/mysql/logs/mysql-bin
log_warnings = 2
max_allowed_packet = 100M
max_binlog_size = 1024M
max_connect_errors = 20
max_connections = 512
max_heap_table_size = 64M
net_read_timeout = 600
net_write_timeout = 600
query_cache_limit = 8M
query_cache_size = 128M
server-id = 1
skip_name_resolve
slave_net_timeout = 60
thread_cache_size = 8
thread_concurrency = 24
tmpdir = /var/tmp
tmp_table_size = 64M
transaction_isolation = READ-COMMITTED
wait_timeout = 57600
net_buffer_length = 1M

# MyISAM
bulk_insert_buffer_size = 64M
key_buffer_size = 384M
myisam_recover_options = BACKUP,FORCE
myisam_sort_buffer_size = 128M

# InnoDB
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 25G
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
#innodb_lazy_drop_table = 1
innodb_log_buffer_size = 16M
innodb_log_files_in_group = 3
innodb_log_file_size = 1024M
innodb_max_dirty_pages_pct = 90
innodb_locks_unsafe_for_binlog = 1

[client]
default-character-set = utf8

[mysqldump]
max_allowed_packet = 16M

任何線索將不勝感激!

作為一種解決方法,我建議創建一個像舊表一樣的新表,添加索引,從舊表中插入數據(可能會合理地分塊),然后切換到新表。 在您的情況下,檢查要用於數據的存儲引擎聽起來是個好主意-如果您有要處理的原始數據,則也許可以選擇“ ARCHIVE”。 或者,如果您的數據中保留有任何類型的結構/“關系”信息,請嘗試對數據模型進行規范化並縮小表的大小。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM