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. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
    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)"


share|improve this question
up vote 0 down vote accepted

See these previous answers:

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 '14 at 18:35
dunce1, have you done the script? How is it?! Please, share it. – user35268 Mar 6 '14 at 15:18
@dunce1 ^^^^^^^ – Jack Douglas Mar 6 '14 at 15:20
You can find the script in my question and yes, it works. – dunce1 Mar 8 '14 at 20:55

Your Answer


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.