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:
Open your MySQL client and connect to your database.
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.
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
Asked: 2021-11-07 11:00:00 +0000
Seen: 11 times
Last updated: Aug 07 '22
How can multiple queries be merged into a single stored procedure in MySQL?
What does "waiting for handler commit" mean in relation to the slow writes experienced in MySQL 8?
How can Spring Boot and Mysql be utilized for CRUD operations?
How can I use sqlalchemy to merge JSON within a column of mysql?
Retrieve all rows in which two IDs appear for the first time.
What are the benefits of choosing sqlalchemy.types instead of sqlalchemy.dialects.mssql?