Ask Your Question
4

What is the correct way of using LOAD DATA LOCAL INFILE IGNORE 1 LINES to update a table that already exists?

asked 2021-11-07 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-08-07 17:00:00 +0000

woof gravatar image

Assuming you have a CSV file named "data.csv" with the same column names as your existing table, here is an example of how to use LOAD DATA LOCAL INFILE IGNORE 1 LINES to update a table that already exists:

  1. Open your MySQL client and connect to your database.

  2. Run the following query to load the CSV file into the table:

LOAD DATA LOCAL INFILE 'data.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;

Replace "table_name" with the name of your existing table.

This query will insert all of the data from the CSV file into your existing table, ignoring the first line (which is assumed to be a header row).

If there are any columns in the CSV file that don't exist in the table, they will be skipped.

Note: Make sure that the CSV file is in the correct format and that it matches the structure of your table. Also, make sure that the file is located in the correct directory on your local machine.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-11-07 11:00:00 +0000

Seen: 18 times

Last updated: Aug 07 '22