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

#!/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

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

BETA Snippet explanation automatically generated by OpenAI:

No explanation generated yet.

Snippet By Dev Dojo

·

Created June 12th, 2021

·

Report Snippet