bash - A better way to execute multiple MySQL commands using shell script -


i write *.sh script execute multiple mysql commands.

currently, can following

mysql -h$host -u$user -p$password -e "drop database $dbname;" mysql -h$host -u$user -p$password -e "create database $dbname;" mysql -h$host -u$user -p$password -e "another mysql command" ... 

is there way avoid typing " mysql -h$host -u$user -p$password -e" every time want execute mysql command?

i think can execute mysql statements text file, example

here cmds.txt file contains mysql commands:

select cola tablea; select colb tableb; select colc tablec; 

to execute them using shell script, type

mysql -h$host -u$user -p$password db_dbname < cmds.txt 

this way, separate mysql commands shell script.

you may want script display progress information you. can invoke mysql "--verbose" option.

for more information, see https://dev.mysql.com/doc/refman/5.6/en/mysql-batch-commands.html


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -