To selectively import particular sections or columns from a CSV file into a mySQL database, you can use the LOAD DATA command with the following syntax:
LOAD DATA [LOCAL] INFILE 'file.csv'
[REPLACE | IGNORE]
INTO TABLE table_name
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(column1, column2, column3, ...)
In this command, you need to replace:
file.csv
with the path to your CSV filetable_name
with the name of the table you want to import the data intocolumn1, column2, column3, ...
with the names of the columns you want to importYou can also add more options to the LOAD DATA command to customize the behavior, such as specifying a different delimiter or enclosure character, or setting a different line terminator.
Note that if you don't want to import all columns from the CSV file, you need to list only the columns you want to import in the last line of the command, and make sure the column names match the order and syntax in the CSV file. You can also skip the optional IGNORE 1 LINES
statement if your CSV file does not have a header row.
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: 2023-06-15 15:25:48 +0000
Seen: 11 times
Last updated: Jun 15 '23
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?