Import a folder of .sql files into one database

I want to import a number (over 100) .sql files into one database. I can do it in one

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

But I have a lot, so I tried this, but he did not declare an “ambiguous redirect”

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

Is there any other approach that I can use from the command line for this?

+4
source share
4 answers

Try:

 find . -name '*.sql' | awk '{ print "source",$0 }' | mysql --batch -u root -p db_name 
+6
source

Maybe try

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

would be an effective alternative.

+1
source

I would try something like

 cat * | mysql -u root -p db_name 
+1
source

First merge all your .sql files into one, and then upload the merged file.

To combine multiple .sql files into a directory with your .sql files:

 `copy *.sql all.sql` 

Then upload to your database:

 mysql -u USER -pPASSWORD DATABASENAME < all.sql 
0
source

Source: https://habr.com/ru/post/1499822/


All Articles