use*_*059 3 mysql sql linux bash shell
假设我有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
Run Code Online (Sandbox Code Playgroud)
**
这是脚本:
mysql -uUser -pPassword -hHostDB -e
Run Code Online (Sandbox Code Playgroud)
查询:
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;**
Run Code Online (Sandbox Code Playgroud)
小智 7
-e参数需要一个内联参数,如下所示:
mysql -uUSER -pPASS -hHOST -e "SELECT * FROM db.table;"
Run Code Online (Sandbox Code Playgroud)
小智 5
您应该在不带反引号 (`) 的 shell 脚本中编写查询字符串:
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"
Run Code Online (Sandbox Code Playgroud)