Batch import multiple CSV files into MySQL database
You need to import multiple CSV files into MySQL database and want to find one A way to batch import.
For users running a MAMP server on Mac OSX, there is the following method:
Use a shell script:
#!/usr/bin/env bash cd yourdirectory for f in *.csv do mysql -e "USE yourDatabase LOAD DATA LOCAL INFILE '"$f"'INTO TABLE yourtable" done
chmod +x import.sh
./import.sh
This script iterates through all the CSV files in your CSV folder and imports them into a table named yourtable using the MySQL LOAD DATA LOCAL INFILE statement. Replace yourdatabase with the name of the database you want to import data into, and yourtable with the name of the table you want to import data into.
The above is the detailed content of How to Batch Import Multiple CSV Files into a MySQL Database on MAMP?. For more information, please follow other related articles on the PHP Chinese website!