Skip to content

Instantly share code, notes, and snippets.

@acosonic
Created May 23, 2023 10:27
Show Gist options
  • Save acosonic/4b2e5c70b4c4fe7fe269bd49c9f16c55 to your computer and use it in GitHub Desktop.
Save acosonic/4b2e5c70b4c4fe7fe269bd49c9f16c55 to your computer and use it in GitHub Desktop.
Load CSV file in MySQL serverside with fixing date formats
TRUNCATE TABLE `db`.`table`;
LOAD DATA LOCAL INFILE '/home/ubuntu/file.csv' IGNORE INTO TABLE `db`.`table`
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES (`id`, `Name`,
`Status`, `AccountNumber`, @v1,
@v2, `Business_Street`)
SET Formation_Date = STR_TO_DATE(@v1,'%m/%d/%Y'),
Production_Date = STR_TO_DATE(@v2,'%m/%d/%Y');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment