如何将多个 csv 文件导入 MySQL 数据库 [英] How to Import Multiple csv files into a MySQL Database

查看:53
本文介绍了如何将多个 csv 文件导入 MySQL 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法同时将多个 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

这篇关于如何将多个 csv 文件导入 MySQL 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆