What is the fastest way to load an XML file into MySQL using C#?

后端 未结 8 1028
独厮守ぢ
独厮守ぢ 2020-12-15 09:19

Question

What is the fastest way to dump a large (> 1GB) XML file into a MySQL database?

Data

The data in question is the StackOverflow Creative

相关标签:
8条回答
  • 2020-12-15 09:53

    There are 2 parts to this:

    • reading the xml file
    • writing to the database

    For reading the xml file, this link http://csharptutorial.blogspot.com/2006/10/reading-xml-fast.html , shows that 1 MB can be read in 2.4 sec using stream reader, that would be 2400 seconds or 40 mins (if my maths is working this late) for 1 GB file.

    From what I have read the fastest way to get data into MySQL is to use LOAD DATA.

    http://dev.mysql.com/doc/refman/5.1/en/load-data.html

    Therefore, if you can read the xml data, write it to files that can be used by LOAD DATA, then run LOAD DATA. The total time may be less than the hours that you are experiancing.

    0 讨论(0)
  • 2020-12-15 09:55

    I noticed in one of your comments above that you are considering MSSQL, so I thought I'd post this. SQL Server has a utility called SQMLXMLBulkLoad which is designed to import large amounts of XML Data into a SQL Server database. Here is the documentation for the SQL Sever 2008 version:

    http://msdn.microsoft.com/en-us/library/ms171993.aspx

    Earlier versions of SQL Server also have this utility

    0 讨论(0)
提交回复
热议问题