MySQL load data infile - acceleration?

前端 未结 3 1449
陌清茗
陌清茗 2020-11-28 05:53

sometimes, I have to re-import data for a project, thus reading about 3.6 million rows into a MySQL table (currently InnoDB, but I am actually not really limited to this eng

相关标签:
3条回答
  • 2020-11-28 06:00

    This blog post is almost 3 years old, but it's still relevant and has some good suggestions for optimizing the performance of "LOAD DATA INFILE":

    http://www.mysqlperformanceblog.com/2007/05/24/predicting-how-long-data-load-would-take/

    0 讨论(0)
  • 2020-11-28 06:03

    InnoDB is a pretty good engine. However, it highly relies on being 'tuned'. One thing is that if your inserts are not in the order of increasing primary keys, innoDB can take a bit longer than MyISAM. This can easily be overcome by setting a higher innodb_buffer_pool_size. My suggestion is to set it at 60-70% of your total RAM on a dedicated MySQL machine.

    0 讨论(0)
  • 2020-11-28 06:10

    if you're using innodb and bulk loading here are a few tips:

    sort your csv file into the primary key order of the target table : remember innodb uses clustered primary keys so it will load faster if it's sorted !

    typical load data infile i use:

    truncate <table>;
    
    set autocommit = 0;
    
    load data infile <path> into table <table>...
    
    commit;
    

    other optimisations you can use to boost load times:

    set unique_checks = 0;
    set foreign_key_checks = 0;
    set sql_log_bin=0;
    

    split the csv file into smaller chunks

    typical import stats i have observed during bulk loads:

    3.5 - 6.5 million rows imported per min
    210 - 400 million rows per hour
    
    0 讨论(0)
提交回复
热议问题