Invalid field count in CSV input on line 1

50,929

Solution 1

If you want this to import into that table you have 2 choices:

1) Add a comma before and after the data in every row of your file, or

2) Delete the first and third columns in your table, import the data and then add the 2 columns you deleted back.

Solution 2

If you use phpMyAdmin, then you are allowed to specify column names. When logged into the desired database:

  1. Select the table you want to import to.
  2. Click the Import tab.
  3. Under Format of imported file, select CSV.
  4. In Column names, write out a comma separated list of the columns you want the data imported to.

You can also use mysqlimport if you prefer the shell.

For Example:

shell>mysqlimport --columns=column1,column2 dbname imptest.txt

Solution 3

In Excel I saved the file as "Microsoft Office Excel Comma Separated Values File (.csv)"

In Phpmyadmin:

  1. Select database you want to import table into.
  2. Click import tab.
  3. Select your file. Set FORMAT to CSV
  4. Leave Format-Specific Options alone except for ticking the "The first line of the file contains the table column names" box if you need to
  5. Click GO
  6. You then need to rename the table ( which will be called somthing like "TABLE 5" if its the 5th table in the DB). So select the table and using the Operations tab -> "Rename table to:"
Share:
50,929
user455318
Author by

user455318

Updated on July 09, 2022

Comments

  • user455318
    user455318 almost 2 years

    I am trying to export an ODS file to CSV, but when I import into phpmyadmin - I get "Invalid field count in CSV input on line 1."

    File (it has more than two lines but the scheme is the same):

    "Administração da Guarda Nacional Republicana"
    "Administração de Publicidade e Marketing"
    

    table:

    CREATE TABLE IF NOT EXISTS `profession` (
      `id_profession` int(11) NOT NULL,
      `profession` varchar(45) DEFAULT NULL,
      `formation_area_id_formation_area` int(11) NOT NULL,
      PRIMARY KEY (`id_profession`),
      UNIQUE KEY `profession_UNIQUE` (`profession`),
      KEY `fk_profession_formation_area1` (`formation_area_id_formation_area`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    

    I never do something similar, probably i need to specify the columns. the csv only have one column and the table have three. In this case the file input belongs to profession column

    • Admin
      Admin almost 13 years
      Obviously, the data is in the wrong format, and required fields are missing. You can't import it.
    • OMG Ponies
      OMG Ponies almost 13 years
    • user455318
      user455318 almost 13 years
      so, i can't import a specific column? must be the three fields in this case?