Seamlessly Importing Multiple CSV Files into MySQL Database
Importing data into a MySQL database from CSV files is a common requirement, but manual import can be tedious when dealing with a large number of files. This article explores an efficient batch import solution for importing multiple CSV files simultaneously into a MySQL database.
Solution for Batch CSV Import
To streamline the import process, execute the following shell script:
<code class="bash">#!/usr/bin/env bash # Change to the directory containing your CSV files. cd yourdirectory # Iterate through all CSV files in the directory. for f in *.csv do # Import the current CSV file into the specified MySQL database and table. mysql -e "USE yourDatabase LOAD DATA LOCAL INFILE '"$f"' INTO TABLE yourtable" done</code>
Customization and Usage
Benefits of Batch Import
By leveraging this batch import script, you can seamlessly import multiple CSV files into your MySQL database in a streamlined and time-saving manner.
The above is the detailed content of How to Efficiently Batch Import Multiple CSV Files into a MySQL Database?. For more information, please follow other related articles on the PHP Chinese website!