Batch Import Multiple CSV Files into a MySQL Database
Importing individual CSV files into a MySQL database can be a tedious and time-consuming task, especially when dealing with a large number of files. This issue is particularly prevalent for users with limited time or access to automated tools.
The Solution: A Shell Script for Batch Import
To address this challenge, a straightforward solution is to utilize a shell script that automates the import process for multiple CSV files. Here's a sample shell script that can be used to import CSV files into a MySQL database:
#!/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
This script performs the following actions:
Usage
To use the shell script, follow these steps:
This method effectively automates the import process and eliminates the need for manual operations, saving you significant time and effort.
The above is the detailed content of How to Batch Import Multiple CSV Files into a MySQL Database?. For more information, please follow other related articles on the PHP Chinese website!