Importing CSV data into a table in mySQL database - mysql

Ok so I am trying to import data from a CSV file into mySQL database table. The table is called serial_code, however when I try to upload the CSV file I have an error message. I have tried taking the column names out, also adding NULL to the last column EngineSerialCode and I have also viewed the CSV in a text editor and it shows the columns correctly with , comma.
Invalid column count in CSV input on line 1.
Version of phpMyAdmin and mySQL
Database Fields
CSV Fields I want to import

Ok so I found the issue and it was quite frustrating. I had a serial code in my data that had a "," comma instead of a "-". Also I noticed that my CSV file EngineSerialCode was placed in column E and not D as I only have 4 columns in my database. From the image column C is overlapping column D hence my mistake.

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

Invalid column count in CSV input on line 1 error (Already checked other questions)

So I've seen this question asked many times but I have not found an answer to my issue. I'm using phpmyadmin, I have 1 table with 2 columns and I have a .csv with 2 columns. My csv does not have headers and my columns are separated by ";", already changed it in phpmyadmin to "Columns separated with ;", but I still got the same error. Can anyone help?
edit: I'm using the "Import" option of phpMyAdmin to import my csv
edit2: So I decided to export my table to see how the csv was generated. It exports like this:
"1", "1001"
"2", "1002"
Do you know why? or how can I create an csv file with the same format?
export table
As it says in the manual
When importing data into a table from a CSV file where the table has an ‘auto_increment’ field, make the ‘auto_increment’ value for each record in the CSV field to be ‘0’ (zero). This allows the ‘auto_increment’ field to populate correctly.
see https://docs.phpmyadmin.net/en/latest/import_export.html
So, what worked for me was: I exported the table as an csv and worked over that. After I was done, I imported this modified csv and it worked. It must've been what nbk said about termination, so I guess in a way that was the answer

Importing csv file in Cassandra Database throws error Record #0 (line 1) has the wrong number of fields 1 instead of 7

AM using the copy method for copying the CSV file into the Cassandra tables.. But am getting records error of has wrong number of fields .
Query is ---COPY activity FROM 'Detail.csv' with HEADER=TRUE
i have my activity as column family with 7 fields
but in my csv file everything is separated by semicolon
Error is Record #0 (line 1) has the wrong number of Fields (1 instead of 7)
Above image is Screen Shot of CSV file
in my csv file everything is separated by semicolon
The default behavior of the COPY command uses a comma as a delimiter. Since your file is (apparently) semi-colon-delimited, it will see the entire row as one field (unless the data contains commas). Try setting the DELIMITER option in your WITH clause.
COPY activity FROM 'Detail.csv' WITH HEADER=TRUE AND DELIMITER=';';
And as a suggestion, I have always had more luck getting COPY to work properly when listing-out the columns to import:
COPY airplanes (name, manufacturer, year, mach) FROM 'temp.csv';

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.

Categories