What is the best way to achieve speedy inserts of large amounts of data in MySQL?

后端 未结 6 1530
无人共我
无人共我 2021-01-05 05:01

I have written a program in C to parse large XML files and then create files with insert statements. Some other process would ingest the files into a MySQL database. This

6条回答
  •  说谎
    说谎 (楼主)
    2021-01-05 05:37

    Really depends on the engine. If you're using InnoDB, do use transactions (you can't avoid them - but if you use autocommit, each batch is implicitly in its own txn), but make sure they're neither too big or too small.

    If you're using MyISAM, transactions are meaningless. You may achieve better insert speed by disabling and enabling indexes, but that is only good on an empty table.

    If you start with an empty table, that's generally best.

    LOAD DATA is a winner either way.

提交回复
热议问题