Morgan Green
Morgan Green

Reputation: 996

Create Sh and Bin File to Execute all SQL Scripts in folder

I'm not sure if this is possible, but if I have a directory with 40+ SQL Scripts in it. Is it possible to make a run_scripts.bat and/or a run_scripts.sh file to execute all SQL scripts in the folder? Sorry I don't have even a start code, but I've been looking around at how this would be done to no avail. Thanks to anyone that can help

Upvotes: 0

Views: 412

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74028

Depending on the database you use (e.g. mysql), you can just run in a loop:

for f; do
    mysql -u $DBUSER -p $DB <$f
done

Then, you can call this on the command line:

$ sh run_scripts.sh *.sql

Upvotes: 1

Related Questions