Solved

Trouble with importing excel (csv) to MySQL

Posted on 2009-04-15
10
398 Views
Last Modified: 2012-06-22
Hey. I am trying to import a file to my MySQL database. I have downloaded an excel-file and then corrected it, so it fits properly with my table, I would think (i am still pretty new to MySQL so I followed a couple guides). I saved the excel-file as a .csv and went to phpMyAdmin and chose "Import". But it gives me this error
"Invalid field count in CSV input on line 1."
I have no idea what is wrong. It looks pretty much right in my opinion
Please help me!
0
Comment
Question by:MisterHamper
  • 6
  • 4
10 Comments
 

Author Comment

by:MisterHamper
ID: 24146704
In the picture is my table. It has an id with autoincrement

And in the code snippet is the start of my excel.csv file. I also tried deleting the first line, and importing it, but the same error came up!
"id","food_name","gmwt_desc1","gmwt1","gmwt_desc2","gmwt2","calories","total_fat","saturated_fat","dietary_fiber","protein","cholesterol","sodium"
,"BUTTER,WITH SALT","1 cup",227,"1 tbsp","14,2",717,"81,11","51,37",0,"0,85",215,576
,"BUTTER,WHIPPED,WITH SALT","1 cup",151,"1 tbsp","9,4",717,"81,11","50,49",0,"0,85",219,827
,"BUTTER OIL,ANHYDROUS","1 cup",205,"1 tbsp","12,8",876,"99,48","61,92",0,"0,28",256,2
,"CHEESE,BLUE","1 oz","28,35","1 cubic inch","17,3",353,"28,74","18,67",0,"21,4",75,1395
,"CHEESE,BRICK","1 cup, diced",132,"1 cup, shredded",113,371,"29,68","18,76",0,"23,24",94,560
,"CHEESE,BRIE","1 cup, melted",240,"1 cup, sliced",144,334,"27,68","17,41",0,"20,75",100,629
,"CHEESE,CAMEMBERT","1 cup",246,"1 oz","28,35",300,"24,26","15,26",0,"19,8",72,842

Open in new window

Z-56.jpg
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 24148344
Its a not-null autoincrement field.
Try allowing null.
0
 

Author Comment

by:MisterHamper
ID: 24148486
Hey! I just tried changing id to null - but it just reverts back to "null: no" again right after.
It says this when I change id to null, but still it is still "null: no". It's strange
"Table foodcomp has been altered.
SQL query:
ALTER TABLE `foodcomp` CHANGE `id` `id` INT( 10 ) NULL AUTO_INCREMENT "
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 21

Expert Comment

by:theGhost_k8
ID: 24148489
Your number of fields are different in CSV and in your  table structure,
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 24148561
You're missing "carbohydrates" field  and that is causing problem as its not matching the number of columns in table.
0
 

Author Comment

by:MisterHamper
ID: 24148590
Ahh yes you was right! Good observation. I just removed "carbohydrates" from my table, so now they should look the same both of them.

But it still gave me this error: Invalid field count in CSV input on line 1.
I think it might have something to do with "id". Is "id" written correctly in my excel.csv file for it to auto-increment, because I am not sure at all?
0
 
LVL 21

Accepted Solution

by:
theGhost_k8 earned 500 total points
ID: 24148704
I've observed that if you don't give newline at end of the file it will give "Invalid format of CSV input on ..."
Remove field-names from line 1 and also add new line at the end of file.
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 24148712
Optionally you can give :
Number of records(queries) to skip from start  = 1
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 24148737
I hope your providing proper options while importing csv file:
Fields terminated by = , instead of default "
0
 

Author Comment

by:MisterHamper
ID: 24148891
Ahh yes it seems it is working now. I tried skipping 1 line, and remembered to use "Fields terminated by = , "

Thanks alot, my good sir! :D Have a nice day
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question