Home >Database >Mysql Tutorial >How can I batch import multiple CSV files into MySQL efficiently?
Batch Importing Multiple CSV Files into MySQL
Importing multiple CSV files into a MySQL database can be a time-consuming task when done manually. This article provides a solution for batch importing CSV files, significantly reducing the manual effort required.
Using a Shell Script for Batch Importing
One efficient way to import multiple CSV files is by utilizing a shell script. Here's an example script that you can modify to suit your environment:
#!/usr/bin/env bash cd yourdirectory for f in *.csv do mysql -e "USE yourDatabase LOAD DATA LOCAL INFILE '"$f"'INTO TABLE yourtable" done
Explanation of the Script:
Usage:
To use this script, follow these steps:
This script will automatically import all the CSV files in the current directory into the specified database and table.
The above is the detailed content of How can I batch import multiple CSV files into MySQL efficiently?. For more information, please follow other related articles on the PHP Chinese website!