How to Import Multiple csv files into a MySQL Database

后端 未结 9 1620
深忆病人
深忆病人 2020-11-30 06:14

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

I\'m on Mac OSX running a MAMP server.

I have

9条回答
  •  無奈伤痛
    2020-11-30 06:33

    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
    

提交回复
热议问题