Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am looking for a way to insert all my csv files into mySQL without having to write several "LOAD DATA INFILE" statements as I have many csv files I need to insert and the files themselves are very large. I have tried *.csv but this does not work. Was wondering if anyone could help me out...

Thanks ahead of time.

Edit: I wrote a script which worked:

for f in /var/lib/mysql/[insert name of database here]/*.csv
do
    mysql -e "LOAD DATA INFILE '"$f"' INTO TABLE [nameoftable] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES" -u [username] --password= [password] [name of database]
echo "Done: '"$f"' at $(date)"
done

Cheers!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

See these previous answers:

http://stackoverflow.com/questions/8538995/how-to-import-multiple-csv-files-into-a-mysql-database

http://stackoverflow.com/questions/6552042/mysql-loading-multiple-files-into-a-table

Essentially, no. But it's easy to script this to get a similar result (e.g. one command to import multiple files using a loop).

share|improve this answer
    
I wrote a script which worked. Will add that to my question for people to use as an example when they input their csv files. –  dunce1 Feb 1 at 18:35
    
dunce1, have you done the script? How is it?! Please, share it. –  Diego_C Mar 6 at 15:18
    
@dunce1 ^^^^^^^ –  Jack Douglas Mar 6 at 15:20
    
You can find the script in my question and yes, it works. –  dunce1 Mar 8 at 20:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.