I have a single csv file with data that I am trying to load into MySQL using LOAD DATA. My problem is the csv file has data that belongs in 3 separate tables. Line 1 goes into table1, line 2-3 goes into table 2, and all remaining lines go into table 3. I can use IGNORE 3 LINES for the 3rd table, but not sure how to ignore lines after my required data for the first 2 tables.
Here is my LOAD DATA so far:
LOAD DATA INFILE 'data.csv' INTO TABLE tbl_name1
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
LOAD DATA INFILE 'data.csv' INTO TABLE tbl_name2
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES;
LOAD DATA INFILE 'data.csv' INTO TABLE tbl_name3
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 3 LINES;
Related
I'm trying to Load a CSV file into my MySQL database,
But I would like to skip the first line.
I fact It contains the name of my columns and no interesting data.
Here is the query I'm using:
LOAD DATA LOCAL INFILE '/myfile.csv'
INTO TABLE tableName
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
(column,column,column);
LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES;
(reference)
For those curious, IGNORE N LINES should be after the separator qualifiers:
LOAD DATA LOCAL INFILE '/myfile.csv'
INTO TABLE tableName
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(column,column,column);
Try this:
IGNORE N LINES
LOAD DATA INFILE "/path/to/file.csv"
INTO TABLE MYTABLE
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;
I am trying to load data from Excel/ CSV file in MYSQL DB?
What is wrong with this code??
LOAD DATA INFILE "D:/MY_SQL_Practice/Sales_Data.csv" INTO TABLE sales_data
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
ignore 1 rows;
Like describe on mysql reference, https://dev.mysql.com/doc/refman/8.0/en/load-data.html
The example used only ' and never " on syntax :
LOAD DATA INFILE '/tmp/jokes.txt' INTO TABLE jokes
FIELDS TERMINATED BY ''
LINES TERMINATED BY '\n%%\n' (joke);
Can you try this syntax ? replace " by ':
LOAD DATA INFILE 'D:/MY_SQL_Practice/Sales_Data.csv' INTO TABLE sales_data
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
ignore 1 rows;
I wanted to import the csv file into the mysql. I am using this following code:
LOAD DATA local INFILE 'D:\20507.csv'
INTO TABLE rohit1
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
But it is not working; it shows only first column record?
Help me to out.
Try this :
LOAD DATA local INFILE 'D:/20507.csv' INTO TABLE rohit1 FIELDS TERMINATED
BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;
Is it possible have a query that will do the following...
Load Data Local for a CSV file
Create a table
Create the fields based off the first row of the csv
Insert the data from the csv into this new table
this is what I have right now:
LOAD DATA LOCAL INFILE 'C:\\CaliberMap.csv'
INTO TABLE sefeed_calibermap
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
The following is skipping the first column in the table
$load ="LOAD DATA INFILE '$inputFile' INTO TABLE $tableName FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 LINES";
The infile has proper data in proper columns
What's wrong ?