通过bash文件执行命令[关闭](Executing command through bash file [closed])
我想通过bash文件执行mysql命令,因为我是shell脚本的新手我尝试了一个命令mysql -uroot -proot ,它运行正常。 但我想从数据库testDB进一步显示这个脚本(select * from product;)。
i want to execute mysql commands through a bash file, since am new to shell script i tried a command mysql -uroot -proot which worked fine. But i want to display a table further with this script(select * from product;) from database testDB.
最满意答案
如果您希望运行单个查询,请尝试这样的操作
mysql -u USER -pPASSWORD -h HOSTNAME -e "SQL_QUERY"若要运行多个SQL查询或单个多行SQL查询,请使用EOF构造。
示例 -
mysql -u USER -pPASSWORD <<EOF SQL_QUERY 1 SQL_QUERY 2 SQL_QUERY N EOF这里有一篇写得很好的文章
If you wish to run a single query then try something like this
mysql -u USER -pPASSWORD -h HOSTNAME -e "SQL_QUERY"To run multiple SQL queries or a single multi-line SQL query, Use the EOF construction.
Example -
mysql -u USER -pPASSWORD <<EOF SQL_QUERY 1 SQL_QUERY 2 SQL_QUERY N EOFThere is a well writen article here
更多推荐
发布评论