其他分享
首页 > 其他分享> > 加载数据文件中的文件禁用/启用键性能

加载数据文件中的文件禁用/启用键性能

作者:互联网

我有一张约有700万行的表.每天一次,我需要将大约200,000新行批量导入此表.为此,我首先使用LOAD DATA INFILE禁用表上的键,然后重新启用表上的键.

我遇到的问题是ALTER TABLE my_table ENABLE KEYS语句.
大约需要15分钟才能完成.我试图通过增加myisam_sort_buffer_size来提高性能,但这似乎无济于事.还有其他想法吗?

解决方法:

您可以尝试使用外部MySQL工具,例如mysqladmin和myisamchk.它们位于常规安装的/usr/local/mysql / bin路径中.

来自MySQL网站的解决方案路径:

  • Execute a FLUSH TABLES statement or a mysqladmin flush-tables command.

  • Use myisamchk –keys-used=0 -rq /path/to/db/tbl_name. This removes all
    use of indexes for the table.

  • Insert data into the table with LOAD DATA INFILE. This does not update any
    indexes and therefore is very fast.

  • If you intend only to read from the table in the future, use myisampack to
    compress it. See Section 13.4.3.3,
    “Compressed Table Characteristics”.

  • Re-create the indexes with myisamchk -rq /path/to/db/tbl_name. This creates the index tree in memory before
    writing it to disk, which is much
    faster that updating the index during
    LOAD DATA INFILE because it avoids
    lots of disk seeks. The resulting
    index tree is also perfectly balanced.

  • Execute a FLUSH TABLES statement or a mysqladmin flush-tables command.

mysql official documents

标签:load-data-infile,sql,mysql
来源: https://codeday.me/bug/20191106/2001988.html