2014-10-27 58 views
1

我在外殼有這樣的MySQL腳本:選擇到變量或實現內選擇在shell腳本的MySQL的選擇

#!/bin/bash 
keyOrPass=$1 
intercom=$2 
flat=$3 
number=$4 
mysql -ulogin -ppassword db_name << EOF 
select codeGuestEmail, codePrivateEmail from mbus_clients WHERE flat=$flat and domophone=$intercom; 
select * from mbusClientKeys where id_client=(select id from mbus_clients WHERE flat=${flat} and domophone=${intercom}); 
EOF 

它給了錯誤,當我添加第二個查詢:right syntax to use near ''當我嘗試聲明變量和使用select進入存儲過程中,這不起作用。從previous question也錯誤與EOF是實際的。
UPDATE 我試圖好好嘗試一下也工作:

SET @id := 1; 
select id into @id from mbus_clients WHERE flat=${flat} and domophone=${intercom}; 

right syntax to use near 'select id into @id from mbus_clients WHERE flat=200 

UPDATE2 在以前的更新錯過了分號。 現在正常工作。

回答

1
SET @id := 1; 

集工作正常,但不是 set id=1,因爲它是在存儲過程中應:=