Re: Import Multiple CSV Files in Windows
Posted by:
Ian Coan
Date: September 04, 2015 01:08PM
The following is the code I used when trying the mysql.exe command. This also did not work. However this is the code that was generated from HEIDI SQL software when I tried to import just one CSV file at a time. That worked flawlessly, one at a time. I want to make it do it multiple times for all CSV files I have from a batch file. I obscured filed names, database name and table name. Any suggestion as to an exact code example from start to finish on how to make this work? What you see here is an example I found while searching. I don't even know what it does.
FOR %%f IN ("*.csv") DO (
set old=%%~dpnxf
set new=!old:\=\\!
mysql -e -u root -pPASSWORD "LOAD DATA LOW_PRIORITY LOCAL INFILE '"!new!"' INTO TABLE `DB NAME`.`TABLE NAME` CHARACTER SET utf8 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n' IGNORE 3 LINES (`FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`, `FILED NAME`)"
echo %%~nxf DONE
)