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
Post a Comment