phpMyAdmin – Invalid field count in csv input on line 1

I was trying to import a massive csv dataset into phpMyAdmin and it kept throwing error: Invalid field count in csv input on line 1

This was very annoying as it was all being done the way it always works for me!

To solve this I had to do the following:

  • Import
  • Browse for your csv file.
  • Select CSV using LOAD DATA (rather than just CSV)
  • Change “Fields terminated by” from “;” to “,”
  • Make sure “Use LOCAL keyword” is selected.
  • Click “Go”

Done!

Still having problems? Let me know..


Share This Article

Related Posts

Comments

  1. Karensanity September 10, 2010

    Thank You. This saved me a lot of time.

  2. guy September 14, 2010

    thanks this worked for me

  3. Harry Seager October 20, 2010

    Hi, I am now getting the following error: #1148 – The used command is not allowed with this MySQL version.

    Thanks.

    • Andrew February 9, 2011

      Make sure to enclose all the values in ” and end lines as \n

      “ERROR 1148 (42000): The used command is not allowed with this MySQL version” can be caused from this.

  4. Tom November 9, 2010

    Good tip. Saved me a ton of time. Thanks!

  5. geekmate November 29, 2010

    thank you sooooo much!!! this has saved me so many processes!

  6. Aaron December 1, 2010

    Thank you so much, saved me!!!

  7. Steve December 11, 2010

    Thanks dude – this just saved me!.

  8. kuldeep Vyas December 31, 2010

    Thanks it works fine.

  9. Riverrat January 21, 2011

    Thanks this saved me days of agro.
    Little note for others phpmyadmin throws an error message but it still worked!

  10. Elaine January 24, 2011

    Many thanks !!!
    I had been trying for hours to get the phpMyAdmin Import to work with a simple .csv file. Did not find this documented elsewhere. This was a big help – it worked perfectly.

  11. Winston January 25, 2011

    Thank you!!!! I have pulled out my hair on this for the past 3 hours and now with your fix it’s in there in less than 1 min. Amazing.

    thank you again for sharing. It really does help

    • Andrew February 9, 2011

      No problem!

  12. Res February 6, 2011

    Awesome! THANK YOU

  13. thomas February 9, 2011

    It Work!,
    however it will only import one line of my excel/csv file, instead of 200 lines.
    Anybody any idea what the problem is?
    thx

    • Andrew February 9, 2011

      What is the encoding of your file?
      Convert it to UTF-8 so that new line breaks are seen correctly otherwise the character encoding may be stopping it from seeing multiple entries otherwise.

  14. Ashis February 10, 2011

    Thanks !!

    It works for me :) ) yey

  15. Ramachadnran February 18, 2011

    Really nice thing it helped to come out with the head ache of 3 hours . I want to thank ypu from my heart

    • Andrew February 18, 2011

      Glad to hear it helped you out!

  16. Mel's Video Of The Day! February 27, 2011

    Only had one hand full of hair left when I found this page. THANK YOU for posting this, it saved me a lot of works.

  17. Adam March 8, 2011

    Ahh, thanks Andrew, hopefully this will work!

  18. Bernie Dodge March 9, 2011

    This article got me close to a solution, but the system would only import 1 line. What fixed it was changing “auto” to “\r”.

    Maybe it’s a Mac thing. The csv file came originally from Filemaker Pro. Anyway, hope that helps others. Thanks for getting me on the right road!

    • Kika September 17, 2011

      Perfect! my files also came from FileMaker and the “\r” is what makes it work

  19. Farhan March 9, 2011

    Thanks this helped me save hours

  20. Patrick March 22, 2011

    Hi, still can’t get it to work though. I have 6 fields. the first field is the ID field, which is AutoIncrement. However, in my csv file, i have 5 fields only, so as not to “corrupt” the auto-increment. I have also tried, puting 6 fields in my csv file. And I have tried typing the field names in “column names” under “format of imported file”. I prepared my csv file from excel, export as csv file, with the first column, blank (leaving it for the auto-increment).I have also tried not leaving it blank. All doesnt seem to work. Sometimes, it gives me the “invalid field count” error message. At other times, depending on the file I use, the apache just shuts down. would appreciate any help. Thanks!

    • Andrew March 22, 2011

      Hi Patrick,
      For your auto-increment field you need to leave it blank for the whole column except for the very first item which you can put a value in, you then delete that value from the csv file once it has been saved. Excel will delete the whole column from the csv if it does not have values in it.
      Does this make sense?

  21. Patrick March 22, 2011

    I am sorry. I forgot to mention that in my excel file, i do have column names. I have tried, with and without column names. both dont seem to work.

  22. Conor March 25, 2011

    Many thanks Andrew (from Ireland!!)

    • Andrew March 25, 2011

      No Problem Conor!

  23. Andrew April 14, 2011

    Man, Thank you. I was at the point of throwing things. B/C my import wouldn’t work. Nice blog, check mine out sometime. http://g00t.com.

  24. Modesto Betancourth April 23, 2011

    Thanx a lot for this post, a year later it’s still valid, saved me a lot of time and a big headache

    Kudos

    • Andrew April 23, 2011

      Glad it helped you!
      Take a look at some of our other posts if you haven’t already!

  25. Udana April 26, 2011

    thanks, you saved a lot of my time.. is this the permanent solution for this problem?

    • Andrew April 26, 2011

      Yes, this is the way you should do it as it better handles your data.

  26. ct May 1, 2011

    why the data is not insert into my database??it just have the column name…

    • Andrew May 1, 2011

      You should not have the column names as your first row of data.
      Make sure that the field terminations are correct and that any auto-increment fields are blank.

  27. melanie May 5, 2011

    Like all the others – thank you. You saved me time as well.

  28. Shyamal May 6, 2011

    It’s absolute true. This is works well with most of the CSV file. Thanks for your post

  29. Dijo David May 26, 2011

    Thanks a lot!! Brilliant!

  30. hassan June 2, 2011

    Great Article i like it so nice of you
    Thanks Alot it Save My 3 to 4 days i done it!!!!!!!!!!!

  31. a bear June 21, 2011

    Thank you. I was struggling and this fixed it!

  32. shiva July 12, 2011

    #1148 – The used command is not allowed with this MySQL version

    • Andrew July 13, 2011

      “If LOAD DATA LOCAL INFILE is disabled, either in the server or the client, a client that attempts to issue such a statement receives the following error message:
      ERROR 1148: The used command is not allowed with this MySQL version”

      • Charley August 20, 2011

        This might help (depending on how mySQL was setup):

        SET @@global.local_infile = ‘On’;

        …run your SQL now and when it’s done remember to turn it off again…

        SET @@global.local_infile = ‘Off’;

        • Andrew August 22, 2011

          Thanks Charley!

  33. GBP July 25, 2011

    thank you so much this has saved me tons of time :D keep up the good work!

  34. Marc August 7, 2011

    Thank you for saving me a lot of time!

  35. kalar August 29, 2011

    Thanks a lot. You just save my butt.

  36. Jerry September 5, 2011

    This workaround didn’t work for me. Maybe because I had utf8 data (Ukrainian language).

    What worked though was:
    1. Upgrade to the latest phpMyAdmin (3.4.4)
    2. Import the .xlsx file as is

    I was impressed.

    • Andrew September 5, 2011

      @Jerry, thank you for your post, I’m sure it will help many others that find this page.

  37. Steph September 10, 2011

    Thank you so much. *offers a cherry lifesaver*

  38. wordman September 29, 2011

    Andrew,

    Hello and a big THANK YOU from Las vegas! Your tech tip worked for me as well, I found what I was looking for with this comment you made to another poster:

    “For your auto-increment field you need to leave it blank for the whole column except for the very first item which you can put a value in, you then delete that value from the csv file once it has been saved. Excel will delete the whole column from the csv if it does not have values in it.
    Does this make sense?”

    I’ll admit, the wording confused me somewhat, specifically, how do I delete a value from a saved file? Not to worry, I added a 1 in the first cell of my AI column in Excel, saved the file, followed your excellent instructions and voila! Perfectly stocked table.

    Thank you! Bookmarked!

    Sincerely,

    wordman

  39. Jamus November 5, 2011

    Cheers for that

  40. Hi Andrew, and thanks for your tutorial!
    It did not work for us 100%, however, gave a good start.

    This worked for us and might help others for multilingual Excel worksheets / csv files:

    1. Export the XLS-Sheet (delete the headline before) from Excel to CSV. You might want to open the CSV with a text editor to see that columns are separated by ;
    3. Go to phpmyadmin, open your database, chose your table.
    4. Click on import. Browse and select your CSV-file.
    5. Change format from “SQL” to “CSV using LOAD DATA”. Leave utf-8 encoding.
    6. Columns terminated by should be: ;
    7. Leave the other settings default, click Go.
    Done.

    This should import all multilingual excel sheets properly.

    All the best ;)

  41. Peter Reguin December 2, 2011

    This worked great. I just wish I knew where to look for directions to get this to work from a web page.

  42. David Carruth January 14, 2012

    Awesome – this needs a Google +1 for sure!!

Trackbacks

  1. Importing CSV files from Excel in MySQL using PhpMyAdmin « Chris Robinson

Add a Comment

Required

Required

Optional

Latest Domains

1. weebly.com
(1 day ago)
2. whpromotions.co.uk
(1 day ago)
3. adsl24.co.uk
(1 day ago)
4. youryoungmodels.net
(1 day ago)
5. enom.com
(1 day ago)
6. dynect.net
(1 day ago)
7. websitewelcome.com
(1 day ago)
8. hostgator.com
(1 day ago)
9. uploading.com
(2 days ago)
10. soccernetghana.com
(2 days ago)

Services

PHP MySQL Apache Flash Air Java C++ Python