MySQL 第 1 行的 CSV 输入中的字段计数无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6169562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:04:48  来源:igfitidea点击:

Invalid field count in CSV input on line 1

mysqlcsvimportphpmyadminload-data-infile

提问by user455318

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."

我正在尝试将 ODS 文件导出到 CSV,但是当我导入到 phpmyadmin 时 - 我收到“第 1 行的 CSV 输入中的字段计数无效”。

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

我从不做类似的事情,可能我需要指定列。csv 只有一列,表格有三列。在这种情况下,文件输入属于职业列

回答by Justin Nafe

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

如果您使用 phpMyAdmin,那么您可以指定列名。当登录到所需的数据库时:

  1. Select the table you want to import to.
  2. Click the Importtab.
  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.
  1. 选择要导入到的表。
  2. 单击导入选项卡。
  3. 导入文件的格式下,选择CSV
  4. Column names 中,写出要导入数据的列的逗号分隔列表。

You can also use mysqlimport if you prefer the shell.

如果您更喜欢 shell,也可以使用 mysqlimport。

For Example:

例如:

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

回答by Gareth

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

如果您希望将其导入该表,您有 2 个选择:

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

1) 在文件每一行的数据前后添加一个逗号,或

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

2)删除表中的第一列和第三列,导入数据,然后将删除的两列添加回去。

回答by user61629

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

在 Excel 中,我将文件另存为“Microsoft Office Excel 逗号分隔值文件 (.csv)”

In Phpmyadmin:

在 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:"
  1. 选择要导入表的数据库。
  2. 单击导入选项卡。
  3. 选择您的文件。将格式设置为 CSV
  4. 如果需要,除了勾选“文件的第一行包含表列名称”框外,单独保留特定于格式的选项
  5. 点击前往
  6. 然后您需要重命名该表(如果它是数据库中的第 5 个表,它将被称为“表 5”之类的东西)。因此,选择表并使用“操作”选项卡 ->“将表重命名为:”

回答by yasin

Make sure your uploading csv file only not excel file and then follow the below steps

确保您只上传 csv 文件而不是 excel 文件,然后按照以下步骤操作

1 Import

1 进口

2 Browse for your csv file.

2 浏览您的 csv 文件。

3 Select CSV using LOAD DATA (rather than just CSV)

3 使用 LOAD DATA 选择 CSV(而不仅仅是 CSV)

4 Change “Fields terminated by” from “;” to “,”

4 将“字段终止于”从“;”更改为 到 ”,”

5 Make sure “Use LOCAL keyword” is selected.

5 确保选择了“使用本地关键字”。

Click “Go”

回答by YugaPratama

  1. Go to Import tab

  2. Browse for the csv file.

  3. Select "CSV" on Format on imported file tab

  4. Checklist the "Ignore duplicate rows"

  5. Change “Fields terminated by” from “;” to “,”

  1. 转到导入选项卡

  2. 浏览 csv 文件。

  3. 在导入的文件选项卡上的格式上选择“CSV”

  4. 核对清单“忽略重复行”

  5. 将“字段终止于”从“;”更改为 到 ”,”

note : you better check the data that already imported. the first row of the data usually contains the header of each column on the table which you imported to csv file. delete the first row after you imported the csv file

注意:您最好检查已导入的数据。数据的第一行通常包含您导入到 csv 文件的表中每一列的标题。导入csv文件后删除第一行

回答by HEENA AGGARWAL

you need to check the "The first line of the file contains the table column names (if this is unchecked, the first line will become part of the data)" and then click on "GO".

您需要勾选“文件的第一行包含表列名(如果不勾选,第一行将成为数据的一部分)”,然后点击“GO”。