gpt4 book ai didi

mysql - 在 shell 脚本中执行 mysql 查询

转载 作者:太空狗 更新时间:2023-10-29 11:25:12 25 4
gpt4 key购买 nike

假设我有 2 个数据库 nm 和 nm_history。我需要从两个数据库中获取记录。如果我在 mysql 中执行查询,它工作正常。但是如果我在 bin/bash 中执行该查询,它会返回以下错误

**

mysql: option '-e' requires an argument
./get_rec.sh: line 4: subscriber_2: command not found
./get_rec.sh: line 4: a_party: command not found
./get_rec.sh: line 4: subscriber_2: command not found
./get_rec.sh: line 4: prov_channel: command not found
./get_rec.sh: line 4: subscriber_2: command not found
./get_rec.sh: line 4: created: command not found
./get_rec.sh: line 4: svc_mgmt_07: command not found
./get_rec.sh: line 4: created: command not found
./get_rec.sh: line 4: subscriber_2: command not found
./get_rec.sh: line 4: svc_mgmt_07: command not found
./get_rec.sh: line 4: subscriber_2: command not found
./get_rec.sh: line 4: a_party: command not found
./get_rec.sh: line 4: svc_mgmt_07: command not found
./get_rec.sh: line 4: msisdn: command not found
./get_rec.sh: line 4: svc_mgmt_07: command not found
./get_rec.sh: line 4: action_type: command not found
./get_rec.sh: line 4: SELECT nm.., nm.., nm.. AS Created, nm_history.. AS terminate FROM nm. INNER JOIN nm_history. ON nm.. = nm_history..
WHERE nm_history..=2: command not found

**

这是脚本:

mysql -uUser -pPassword -hHostDB -e

查询:

SELECT S.`a_party`, S.`prov_channel`, S.`created` AS Created,M.`created` AS terminate FROM nm.`subscriber_1` S INNER JOIN nm_history.`svc_mgmt_06` M ON S.`a_party` = M.`msisdn` 
WHERE M.`action_type`=2;**

最佳答案

-e 参数需要一个内联参数,如下所示:

mysql -uUSER -pPASS -hHOST -e "SELECT * FROM db.table;"

关于mysql - 在 shell 脚本中执行 mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24545276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com