Read large files to MySQL

Source: Internet
Author: User

Originally used in Java read file processing format after the database, run, found that the efficiency is too low, 4G text, more than 40 million lines, estimated to take about 30 days to complete processing.

Data format:

Each line, XXXX | | | XXXXXXX | | | Xxxxxxxxxxxxxxxxx

Data is strictly structured, so query to a method of importing MySQL directly from a file:

Load Data infile

Reference article: http://hunan.iteye.com/blog/752606

The following directives are used:


according to [| | |] Split a row of data into three segments, then each line is identified by \ n, and three pieces of data are stored in three fields respectively.

Successfully imported 47943428 rows!

After importing, we find that there is a \ R presence at the end of each line, removing the \ r symbol

Update Detail_all Set value = Trim (TRAILING ' \ R ' from ' value ');

Remove the opening and final symbols with trim. Reference: http://nameyjj.blog.51cto.com/788669/621932

Run Times Error:

Error code:2013. Lost connection to MySQL server during query600.746 sec

Find a solution: http://www.quora.com/ How-can-i-solve-the-error-code-2013-lost-connection-to-mysql-server-during-query-600-135-sec-error-message

That is, the time-out will be adjusted to large.

Then run the error:

Error code:1205. Lock wait timeout exceeded; Try restarting transaction

Find a solution: http://blog.csdn.net/mchdba/article/details/38313881

I am here to roll back the process is not over, wait for it to end.


Read large files to MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.