How to Import Multiple csv files into a MySQL Database

后端 未结 9 1621
深忆病人
深忆病人 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:34

    I've modified Tom's script to solve few issues that faced

    #!/bin/bash
    
    for f in *.csv
    do
        mysql -e "load data local infile '"$f"' into table myTable fields TERMINATED BY ',' LINES TERMINATED BY '\n'"  -u myUser--password=myPassword fmeter --local-infile
    done
    
    1. load data local infile instead of load data infile : [file to be loaded was local to mysql server]
    2. Added delimiter switches to match my data.
    3. --local-infile to enabled local data load mode on client.

提交回复
热议问题