MyISAM 表大数据装载
-
执行FLUSH TABLES 语句 或者 mysqladmin flush-tables command.
mysql> flush tables allele; -
使用 myisamchk --keys-used=0 -rq /path/to/db/tbl_name 移除表的所有索引
[root@face ~]# myisamchk --keys-used=0 -rq /data2/mysql/data/homo_sapiens_variation_83_38/allele.MYI -
使用LOAD DATA INFILE插入数据,这将不会更新索引因此会更快[下面的数据我执行了3个多小时没有搞定,这个方法20分钟OK]
mysql> LOAD DATA INFILE '/data1/no_use/allele.txt' INTO TABLE homo_sapiens_variation_83_38.allele;uery OK, 1168971231 rows affected (14 min 37.44 sec)
Records: 1168971231 Deleted: 0 Skipped: 0 Warnings: 0
-
如果你的表的数据仅仅是为了读,使用myisampack压缩它。
[root@face ~# myisampack allele.MYICompressing allele.MYD: (1168971231 records)
- Calculating statistics
- Compressing file
52.87%
Remember to run myisamchk -rq on compressed tables
-
使用myisamchk重建索引,这种建立索引树的方式在内存中进行然后写入磁盘,所以速度比load data infile建立索引快因为这样避免了磁盘寻道,而且最后的索引树也非常平衡。
[root@face ~# myisamchk -rq /data2/mysql/data/homo_sapiens_variation_83_38/allele[root@face homo_sapiens_variation_83_38]# myisamchk -rq allele.MYI
- check record delete-chain
- recovering (with sort) MyISAM-table 'allele.MYI'
Data records: 0
- Fixing index 1
myisamchk: error: myisam_sort_buffer_size is too small
MyISAM-table 'allele.MYI' is not fixed because of errors
Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag
[root@face homo_sapiens_variation_83_38]# myisamchk -rq allele.MYI --sort_buffer_size=10G
- check record delete-chain
- recovering (with sort) MyISAM-table 'allele.MYI'
Data records: 0
- Fixing index 1
2783000
-
执行FLUSH TABLES 语句 或者 mysqladmin flush-tables command.
mysql> flush tables allele;