Javamysql batch import data automatic update date_mysql

Source: Internet
Author: User
Javamysql batch import data automatic update date bitsCN.com

During this period, we have been using hadoop and pig to operate on some data. The new data volume generated every week is more than 1 million. for large volumes of data (more than 10 million), insert and update operations, if the insert operation is slow, I tested that it would take more than 20 hours to insert 30 million records using insert (no cluster is used ).

To speed up data insertion and update, mysql provides the load command to greatly speed up data insertion. on my machine, the load operation is about 10 times faster than insert.

The official load command format is as follows:

 LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'    [REPLACE | IGNORE]    INTO TABLE tbl_name    [CHARACTER SET charset_name]    [{FIELDS | COLUMNS}        [TERMINATED BY 'string']        [[OPTIONALLY] ENCLOSED BY 'char']        [ESCAPED BY 'char']    ]    [LINES        [STARTING BY 'string']        [TERMINATED BY 'string']    ]    [IGNORE number LINES]    [(col_name_or_user_var,...)]    [SET col_name = expr,...]
1. if you want to insert data locally, run the following command:

Load data local infile 'name of the data source to be inserted 'into table name of the table to be inserted

2. if you update an existing record, run the following command:

Load data local infile 'name of the data source to be inserted 'replace into table name of the table to be inserted

In some scenarios, the related time needs to be updated when each piece of data is updated. If no update is made, the original time is saved. There are two ways to solve this problem:

Method 1. this method is more common, that is, when inserting or updating, the current time is passed into the database and updated together.

Method 2: When creating a table, run the following command to create a column named "time ":

`time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
BitsCN.com

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.