Invalid field count in CSV input on line 1 - mysql

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

If you use phpMyAdmin, then you are allowed to specify column names. When logged into the desired database:
Select the table you want to import to.
Click the Import tab.
Under Format of imported file, select CSV.
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

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.

In Excel I saved the file as "Microsoft Office Excel Comma Separated Values File (.csv)"
In Phpmyadmin:
Select database you want to import table into.
Click import tab.
Select your file. Set FORMAT to CSV
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
Click GO
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:"

Make sure your uploading csv file only not excel file and then follow the below steps
1 Import
2 Browse for your csv file.
3 Select CSV using LOAD DATA (rather than just CSV)
4 Change “Fields terminated by” from “;” to “,”
5 Make sure “Use LOCAL keyword” is selected.
Click “Go”

Go to Import tab
Browse for the csv file.
Select "CSV" on Format on imported file tab
Checklist the "Ignore duplicate rows"
Change “Fields terminated by” from “;” to “,”
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

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

Related

Invalid column count in CSV input on line 1

I'm trying to import a CVS made from an excel file, but is not working, i'm receiving the following error -> Invalid column count in CSV input on line 1.
Follow the table structure
Follow the cvs file content
Do I need to have an id field in the csv file? Since its auto incremented, do i need to add it?
Follow is the import config of phpmyadmin
Another doubt, for each entry of mysql table, i would like to add an timestamp, is the configuration right? For every entry of the table, a timestamp will be added?
Regards

Values not inserted into table - Bulk insert from csv to ms-access

I am bulk inserting values from a csv file into my access table. Things were working fine,till today I encountered this problem where access inserts all the values expect for one field called BN1. It simply leaves this column balnk when the data is non numeric. This is the batch name of products and in the design the field type is memo (legacy .mdb file so cant change it).
My sample data:
DATE,TIME,PN1,BN1,CH0,CH1,CH2
2019-02-18,16:40:05,test,prompt,0,294,0
2019-02-18,16:40:14,test,1,700,294,0
So in the above data the first row is inserted with a blank value for prompt where as the 2nd row is inserted properly with BN1 as 1.
My code to insert the data:
INSERT INTO Log_143_temp ([DATE],[TIME],PN1,BN1,CH0,CH1,CH2
) SELECT [DATE],[TIME],PN1,BN1,CH0,CH1,CH2
FROM [Text;FMT=Delimited;DATABASE=C:\tmp].[SAMPLE_1.csv]
The path and the file names are correct else it wouldn't have inserted any value
Hi here is how I solved the issue,
Changed the query to bulk insert to,
INSERT INTO Log_143_temp ([DATE],[TIME],PN1,BN1,CH0,CH1,CH2
) SELECT [DATE],[TIME],PN1,BN1,CH0,CH1,CH2
FROM [Text;FMT=CSVDelimited;HDR=Yes;DATABASE=C:\tmp].[SAMPLE_1.csv]
Then add a file named schema.ini in the folder containing the csv file to be imported.
Contents of the schema.ini file,
[SAMPLE_1.csv]
ColNameHeader=True
Format=CSVDelimited
DateTimeFormat=yyyy-mm-dd
Col1="DATE" Text
Col2="TIME" Text
Col3="PN1" Text
Col4="BN1" Text
Col5="CH0" Double
Col6="CH1" Double
Col7="CH2" Double
Now the csv files get imported without any issue.
For additional info on schema.ini visit the following link,
https://learn.microsoft.com/en-us/sql/odbc/microsoft/schema-ini-file-text-file-driver?view=sql-server-2017

Importing an excel .csv file and adding it to a column in phpMyAdmin

I've read through some other posts and nothing quite answers my question specifically.
I have an existing database in phpMyAdmin - a set of pin codes we use to collect contest entries.
The DB has about 10,000 pin codes in it.
I need to add 250 "New" codes to it. I have an excel file that is stripped down to a single column .csv, no header - just codes.
What I need to do is import this into the table named "pin2" and add these to the row called "pin"
The other rows are where entrants would add names and phone numbers, so are all "null"
I've uploaded a screen grab of the structure.
DB Structure http://www.redpointdesign.ca/sql.png
any help would be appreciated!
You need to use a LOAD DATA query similar to this:
LOAD DATA INFILE 'pincodes.csv'
INTO TABLE pin2 (pin)
If the pin codes in the csv file are enclosed in quotes you may also need to include an ENCLOSED BY clause.
LOAD DATA INFILE 'pincodes.csv'
INTO TABLE pin2
FIELDS ENCLOSED BY '"'
(pin)
If you wants to do using csv
Then you need to need to follow these steps
Manually define autoincremented value in first comlumn.
In other column you have to externally define it as a NULL,
otherwise you will get Invalid column count in CSV input on line 1.
because column with no value is not consider by phpmyadmin
Them click on import in phpmyadmin and you are done ..

Importing a Text File into a MySQL through Navicat DB software

I am trying to import a Text File into a MySQL through Navicat DB software.
I am struggling to import(append) a text file into a MySQL table.
The text file fields are seperated by | ;
example : |Name|Email|Address|
When i import this through the Navicat import wizard it ask for " Which delimeter seperates
the fields. So instead of selecting Tabs, ; , or any other i select | as field seperator.
But still the fields in the file do not match(sync) with the fields of the table...
Can anyone suggest any advice here?
I actually have exported the text file from another MySQL DB thru export functionality from PHPMyAdmin,,
I assume your name column is null and the values appear instead in the email column?
I suspect the problem lies in the fact that your fields are not only separated by a pipe, your rows also begin and end with a pipe.
Think of a CSV: name,email,address, not ,name,email,address,, because that would be interpreted as 5 columns, the value of the first and last field being null.
You'll have to choose a different delimiter for your rows and fields.
Beyond that, you can try importing the data into a new table and then write an insert query to map the temp fields to the ones in your database. The screen after the one where you choose the target table has a table where you can map your import fields to the target ones.
Let me know how that works out.

MySql importing from CSV

I have a table with three columns, NODEID, X, Y. NODEID is the primary key and it is set as an INT(4) to be AUTOINCREMENT. I wish to add more data to this table by importing it from a CSV via the phpmyadmin import. Question:
What would be the format of the CSV look like?
Is this possible or is importing basically just to replace the whole data with the CSV?
As of now the CSV looks like:
1,-105.057578,39.785603
2,-105.038646,39.771132
3,-105.013045,39.771727
5,-105.045721,39.762055
6,-105.031777,39.76206
7,-105.046015,39.72835
8,-105.029796,39.728304
10,-104.930863,39.754579
11,-104.910624,39.754644
13,-104.930959,39.74367
16,-105.045802,39.685253
17,-105.032149,39.688557
18,-105.060891,39.657622
20,-105.042257,39.644086
etc...
Change the SQL that phpmyadmin will run to this:
LOAD DATA INFILE '*FILEPATH*'
INTO TABLE *table*
(X, Y);
(You will only have to change the last line)
And your csv should look like
-105.057578,39.785603
-105.038646,39.771132
-105.013045,39.771727
-105.045721,39.762055
-105.031777,39.76206
-105.046015,39.72835
The last line tells MySQL to look for only those two columns of data and insert null for any other columns. The NULL value will be auto-incremented as expected.