Home > Database > Mysql Tutorial > How to Batch Import Multiple CSV Files into a MySQL Database on MAMP?

How to Batch Import Multiple CSV Files into a MySQL Database on MAMP?

Mary-Kate Olsen
Release: 2024-11-02 13:41:30
Original
801 people have browsed it

How to Batch Import Multiple CSV Files into a MySQL Database on MAMP?

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:

  1. Create a file, such as import.sh, and add Replace its content with the following 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
Copy after login
  1. Make sure the script has been given execution permission:
chmod +x import.sh
Copy after login
  1. Run the script in the terminal:
./import.sh
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template