通过bash文件执行命令[关闭](Executing command through bash file [closed])

系统教程 行业动态 更新时间:2024-06-14 16:59:22
通过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 EOF

There is a well writen article here

更多推荐

本文发布于:2023-04-16 19:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/71c67451ec48c89959d5e52b46f4f7e5.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   文件   bash   Executing   closed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!