For Loop to Import a Large Number of .sql Files to MySQL

Here's a script that would import all of the .sql files in your current directory to MySQL.

I usually use that in case there are a lot of separate MySQL tables which need to be imported in one single database:


# Imports all .sql files in your current direcotry

for i in *.sql
    echo "Importing: $i"
    mysql your_db_name < $i

This could be quite useful if you have a lot of tables exported in .sql format which you need to import in a specific database.

Hope that it helps someone :)

Back to DevDojo