0

i am using navicat for this:

I would like to skip 1st column from the csv I am loading. Is there any option for that while using LOAD DATA LOCAL INFILE.

I'm loading data into my database from a CSV file using LOAD DATA LOCAL as follows:

LOAD DATA LOCAL INFILE 'filelocation.csv' 
INTO TABLE 'table'
FIELDS TERMINATED BY ',' 
IGNORE 1 LINES
(@ignore, col1, col2, col3...)

The issue I have is that in my database, the first column is called id, whereas the first column in my csv files is called date. the id field is auto incremented but the id column just fills with my data and date column rows are all 0000-00-00 00:00

How do I go about telling LOAD DATA to load the data from each row into the database starting at the date field?

Akina
  • 39,301
  • 5
  • 14
  • 25
  • Does this answer you question?: [How to skip columns in CSV file when importing into MySQL table using LOAD DATA INFILE?](https://stackoverflow.com/questions/2139069/how-to-skip-columns-in-csv-file-when-importing-into-mysql-table-using-load-data) – Luuk Apr 27 '22 at 11:25
  • ok this worked but i have another issue, the date column in my csv format is general while in database table date is datetime format. so tis is why its giving me 0000 what can i do. and the id is still not starting with 1 but giving me weird numbers – Elias Ayoub Apr 27 '22 at 11:33
  • [LOAD DATA - Input Preprocessing](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-input-preprocessing). Load the value into variable as string value then convert to DATE format. – Akina Apr 27 '22 at 11:36
  • This is another question, which needs details of the CSV file, and info about the creation of the table in the database. Also `weird numbers` is, a bit, a weird statement – Luuk Apr 27 '22 at 11:36
  • ok my csv file has 11 columns starting with date, my database table has 7 starting with id which is auto incriminated , i figured the mapping all data is imported well except for the first 2 which are id and date. my problem is that the date is giving me all zeros while the id is not automatically giving me sequence from 1 to 1000 – Elias Ayoub Apr 27 '22 at 11:48
  • Do not describe. Edit the question, add complete CREATE TABLE for dest. table and a sample of CSV data (2-3 rows). Both - as code-formatted text. – Akina Apr 27 '22 at 11:52

0 Answers0