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

  • Home
  • SEARCH
  • 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 137507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:07:01+00:00 2026-05-11T07:07:01+00:00

What is the fastest way to load data from flatfiles into a MySQL database,

  • 0

What is the fastest way to load data from flatfiles into a MySQL database, and then create the relations between the tables via foreign keys?

For example… I have a flat file in the format:

[INDIVIDUAL]   [POP]  [MARKER]  [GENOTYPE]  'INDIVIDUAL1', 'CEU', 'rs55555','AA'   'INDIVIDUAL1', 'CEU', 'rs535454','GA'   'INDIVIDUAL1', 'CEU', 'rs555566','AT'   'INDIVIDUAL1', 'CEU', 'rs12345','TT'   ...   'INDIVIDUAL2', 'JPT', 'rs55555','AT'   

Which I need to load into four tables:

IND (id,fk_pop,name)   POP (id,population)   MARKER (id,rsid)   GENOTYPE (id,fk_ind,fk_rsid,call)   

Specifically, how does one populate the foreign keys in a way that scales? The figures are in the range of 1000+ individuals, each with 1 million+ genotypes.

  • 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. 2026-05-11T07:07:02+00:00Added an answer on May 11, 2026 at 7:07 am

    There is a simpler way.

    First, make sure you have a UNIQUE constraint on those columns that should have one (name, population, rsid).

    Then use something like the following:

     LOAD DATA INFILE 'data.txt' IGNORE INTO TABLE POP FIELDS TERMINATED BY ','     ENCLOSED BY ''' LINES TERMINATED BY '\n' IGNORE 1 LINES      (@name, population, @rsid, @call);  LOAD DATA INFILE 'data.txt' IGNORE INTO TABLE MARKER FIELDS TERMINATED BY ','      ENCLOSED BY ''' LINES TERMINATED BY '\n' IGNORE 1 LINES      (@name, @population, rsid, @call);  LOAD DATA INFILE 'data.txt' IGNORE INTO TABLE IND FIELDS TERMINATED BY ','      ENCLOSED BY ''' LINES TERMINATED BY '\n' IGNORE 1 LINES      (name, @population, @rsid, @call)      SET fk_pop = (SELECT id FROM POP WHERE population = @population);  LOAD DATA INFILE 'data.txt' IGNORE INTO TABLE GENOTYPE FIELDS TERMINATED BY ','      ENCLOSED BY ''' LINES TERMINATED BY '\n' IGNORE 1 LINES      (@name, @population, @rsid, call)     SET fk_ind = (SELECT id FROM IND where name = @name),     fk_rsid = (SELECT id FROM MARKER where rsid = @rsid); 

    Note where the @ is used to indicate variables, rather than column names. In the first 2 LOAD DATAs, these are just used to ignore data. In the second 2, they are used to look up the foreign keys.

    Might not be very fast, mind :).

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

Sidebar

Ask A Question

Stats

  • Questions 85k
  • Answers 85k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No. It's not possible to achieve this. If a DLL… May 11, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer Firing up Fiddler, we can see that the server responses… May 11, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer You must connect the two tables with a join: SELECT… May 11, 2026 at 5:11 pm

Related Questions

I need to implement a daemon that needs to extract data from a database,
I have an PHP application that I want localized. Currently, the way I'm doing
I am developing a little app that retrieves an XML file, located on a
I have an array of 1000 strings to load into a combo box. What

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.