Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8987393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:46:49+00:00 2026-06-15T21:46:49+00:00

I am trying to load data from a text file into a MySQL table,

  • 0

I am trying to load data from a text file into a MySQL table, by calling MySQL’s LOAD DATA INFILE from a Java process. This file can contain some data for the current date and also for previous days. The table can also contain data for previous dates. The problem is that some of the columns in the file for previous dates might have changed. But I don’t want to update all of these columns but only want the latest values for some of the columns.

Example,

Table

+----+-------------+------+------+------+
| id | report_date | val1 | val2 | val3 |
+----+-------------+------+------+------+  
|  1 | 2012-12-01  |   10 |    1 |    1 |  
|  2 | 2012-12-02  |   20 |    2 |    2 |
|  3 | 2012-12-03  |   30 |    3 |    3 |
+----+-------------+------+------+------+

Data in Input file:

1|2012-12-01|10|1|1
2|2012-12-02|40|4|4
3|2012-12-03|40|4|4
4|2012-12-04|40|4|4
5|2012-12-05|50|5|5

Table after the load should look like

mysql> select * from load_infile_tests;
+----+-------------+------+------+------+
| id | report_date | val1 | val2 | val3 |
+----+-------------+------+------+------+
|  1 | 2012-12-01  |   10 |    1 |    1 |
|  2 | 2012-12-02  |   40 |    4 |    2 |
|  3 | 2012-12-03  |   40 |    4 |    3 |
|  4 | 2012-12-04  |   40 |    4 |    4 |
|  5 | 2012-12-05  |   50 |    5 |    5 |
+----+-------------+------+------+------+
5 rows in set (0.00 sec)

Note that column val3 values are not updated. Also I need to do this for large files as well, some files can be >300Megs or more, and so it needs to be a scalable solution.

Thanks,
Anirudha

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:46:51+00:00Added an answer on June 15, 2026 at 9:46 pm

    It would be good to use LOAD DATA INFILE with REPLACE option, but in this case records will be dropped and added again, so old val3 values will be lost.

    Try to load data into temporary table, then update your table from temp. table using INSERT … SELECT/UPDATE or INSERT … ON DUPLICATE KEY UPDATE statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to load some data from a text file into mysql. I
I was trying to load a data file into mysql table using LOAD DATA
I am trying to load some data from a text file into a vector
I'm trying to load data from a text file on my server using the
I'm trying to create a mysql table from a thesaurus text file I got
I am trying to insert some e mails from a text file into MySQL
Trying to use 'LOAD DATA INFILE' in order to populate a database table from
I am trying to load mysql data from my database from a html select
I'm trying to load and parse json data from an external source into a
I have an XML file containing seed data that I'm trying to load into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.