Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import folder of .sql files into a single database

I want to import a number (over 100) .sql files into a single database. I can do this for one

mysql -u root -p db_name < /tmp/export/data.sql

But I have a lot, so I tried this but it fails stating "ambiguous redirect"

mysql -u root -p db_name < /tmp/export/*

Is there another approach I can use from the command line to do this?

like image 841
Jake N Avatar asked Aug 30 '13 14:08

Jake N


People also ask

How do I import multiple SQL files?

Select File, then Import, then File. Click Multiple Files. Select the files you want to import. Browse for the first file.


3 Answers

Try:

find . -name '*.sql' | awk '{ print "source",$0 }' | mysql --batch -u root -p db_name
like image 109
jacob21 Avatar answered Nov 04 '22 18:11

jacob21


I would try something like

cat * | mysql -u root -p db_name
like image 22
Stepan Stepanov Avatar answered Nov 04 '22 18:11

Stepan Stepanov


Maybe trying

mysql -u root -p db_name < /tmp/export/*.sql

would be an effective alternative.

like image 28
Oluwakayode Dagbo Avatar answered Nov 04 '22 16:11

Oluwakayode Dagbo