如何将多个 csv 文件导入 MySQL 数据库

2021-11-20 00:00:00 import mysql phpmyadmin

有没有办法同时将多个 csv 文件导入到 MySQL 数据库中?某种批量导入?

Is there a way to import multiple csv files at the same time into a MySQL database? Some sort of batch import?

我在 Mac OSX 上运行 MAMP 服务器.

I'm on Mac OSX running a MAMP server.

我有 185 个 csv 文件需要导入到 MySQL 表中.我可以使用 phpMyAdmin 的导入选项卡单独导入它们,但这需要很长时间.有没有人知道有没有更好的方法?

I have 185 csv files that I need to import into a MySQL table. I can import them individually using phpMyAdmin's import tab, but it would take a long time. Does anyone know if there is a better way?

推荐答案

像这样使用 shell 脚本:

Use a shell script like this:

#!/usr/bin/env bash
cd yourdirectory
for f in *.csv
do
        mysql -e "USE yourDatabase LOAD DATA LOCAL INFILE '"$f"'INTO TABLE yourtable"
done

相关文章