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:

#!/bin/bash

##
# Imports all .sql files in your current direcotry
##

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

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