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 6544005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:24:51+00:00 2026-05-25T11:24:51+00:00

I am trying to load a text file into a database. My text file

  • 0

I am trying to load a text file into a database. My text file is about 1.6GB. I need to write a python script to load the text file with all the headers into a database

Any guidelines on how I go about doing this?

thanks

  • 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-05-25T11:24:52+00:00Added an answer on May 25, 2026 at 11:24 am

    Using python is certainly possible. If you’re reading into mysql, you might check out mysql-python. Reading the text file you can use file = open(‘filename’,’r’), and file.readline() to get each line and parse it.

    However… there is an added overhead of using python. If the text file is orderly (that is, one reacord per row, each row having the same number of columns with a consistent delimiter such as a comma, tab, semi-colon, etc), then the most efficient way is to load it directly. In mysql, you’d do this something like:

    LOAD DATA INFILE '/folder/input.dat' INTO TABLE destination_table
    FIELDS TERMINATED BY ',' (id,field_1,field_2,field_3);
    

    If you need some minor modifications to the file, such as changing commas or things at the beginning or end of the line you might use a command line sed (if you’re on *nix or osx… you’ll have to install if you’re on windows).

    Update

    LOAD DATA INFILE will be quickest: http://dev.mysql.com/doc/refman/5.5/en/load-data.html

    When you say “start of article 1. some text 2. some text 3. some text MAINO”, are 1., 2., 3. and MAINO DIFFERENT FIELDS? If you had 2 fields such as a header and article, you might format your text document to look something like:

    This is my header of the article.;;And here is my article, it's a nice
    story about programming.
    My article goes on for many lines.
    And many more.
    <==============================================================================>
    This is my second article header.;;And here is article 2. It is.
    And is.
    Etc.
    <==============================================================================>
    

    Then, you could use LOAD DATA INFILE like:

    LOAD DATA INFILE '/folder/filename.txt' INTO TABLE destination_table
    LINES TERMINATED BY '<==============================================================================>'
    FIELDS TERMINATED BY ';;' (header,article);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying only to load a part of a text file (*.txt) into the
I am trying to import a large text file into a MySQL database. The
I am trying to load some data from a text file into a vector
I am trying to load some data from a text file into mysql. I
I have been trying to load a text file into a combobox, and then
I'm trying to load a large text file into MATLAB. The file has the
I'm trying to load a list of filenames from a text file and then
I have an XML file containing seed data that I'm trying to load into
I have been running into OutOfMemory Exceptions while trying to load an 800MB text
Im trying to load a csv file into a datatable using oledb. This is

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.