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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:07:07+00:00 2026-05-27T10:07:07+00:00

I am trying to import a CSV file into a MySQL database table. The

  • 0

I am trying to import a CSV file into a MySQL database table. The CSV rows look like the following:

"00602"," ","42042","15590","0","0","0","35","9","67","1978","20608","21434","3.1","54700","11384","31.3","30.4","32","18.382809","-67.186759","0","PR","Puerto Rico","U","","787","AGUADA","URB SAN CRISTOBAL","AGUADA","003","72","4","N","0060","","","10380","","Metro","Aguadilla-Isabela-San Sebastián PR","Aguadilla PR MSA","","","","N","0","0","0","0","","0","0","0","0","0","322569","0","","","5456","415","9577","V17136"," "," ","",""
"00602"," ","42042","15590","0","0","0","35","9","67","1978","20608","21434","3.1","54700","11384","31.3","30.4","32","18.382809","-67.186759","0","PR","Puerto Rico","U","","787","AGUADA","COMUNIDAD LAS FLORES","AGUADA","003","72","4","N","0060","","","10380","","Metro","Aguadilla-Isabela-San Sebastián PR","Aguadilla PR MSA","","","","N","0","0","0","0","","0","0","0","0","0","322569","0","","","5456","415","9577","V17136"," "," ","",""

etc...

As you can see, the fields are enclosed in double quotes and separated by commas. However some rows have commas inside the values like so (notice the last value):

"00501"," ","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","40.81518","-73.0455","25","NY","New York","N","","631","HOLTSVILLE","I R S SERVICE CENTER","SUFFOLK","103","36","5","Y","5602","5380","408","35620","35004","Metro","New York-Northern New Jersey-Long Island NY-NJ-PA","New York-Northern New Jersey-Long Island","Nassau-Suffolk, NY PMSA","Northeast","Middle Atlantic","N","7","0","0","0","B","0","0","0","0","0","18640775","2807500","","","0","1","1","V13916","U"," ","New York-Newark-Bridgeport, NY-NJ-CT-PA","Nassau-Suffolk, NY"

This is how my import statement looks like:

LOAD DATA INFILE '/file.csv'
REPLACE INTO TABLE zipcodes 
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n';

But it’s not working as expected. For example, the first inserted row has a column with the following value:

Nassau-Suffolk, NY""00501

instead it should have been:

Nassau-Suffolk, NY

and 00501 should have been inserted as the first column value on the next row.

How to adjust my SQL to work right?

  • 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-27T10:07:08+00:00Added an answer on May 27, 2026 at 10:07 am

    From the MySQL Reference Manual, use the following options instead:

    LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
      FIELDS TERMINATED BY ',' ENCLOSED BY '"'
      LINES TERMINATED BY '\r\n'
    

    Update to match your usage, but the important part is to drop the OPTIONALLY from OPTIONALLY ENCLOSED BY.

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

Sidebar

Related Questions

I'm trying to import a CSV files into my MySQL table using the following
I am trying to import a large CSV file into a MySQL database. I
I am trying to import a CSV file into a MySQL 5.1 database. The
I am writing the following script up import a csv file into a mysql
I am trying to import a txt/csv file into my postgres database from php
I am trying to import a .csv file into my database. I am able
I am trying to import a .csv file into my database. I am able
I'm trying to import a very large .csv file (~4gb) into mysql. I was
I'm trying to load data from a CSV file into a MySQL database, and
I am trying to import a large csv file into MySQL. It's about 1.4

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.