2016-11-09 143 views
-2
#!/bin/bash 
mysql -u root -password << EOF 
use runk_prd; 
SELECT user_push_token FROM users WHERE user_push_token <> 'NULL' | while read guid user_push_token; do 
    echo "pushToken: $user_push_token" 
EOF 

我試圖運行上面的腳本,但而不是返回推列表令牌它給我下面的錯誤循環在查詢輸出:使用bash腳本

mysql: [Warning] Using a password on the command line interface can be insecure. 
ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'while read guid user_push_token' at line 1 

我已經在MySQL網絡應用程序中測試了查詢,並且在那裏工作得很好。

+0

我認爲這個問題是顯而易見的,如果你知道你正在使用的語法的意義; '|而閱讀......'部分顯然是打算由Bash處理,而是作爲輸入傳遞給MySQL。你是否試圖拼湊代碼片段而不理解它們? – ruakh

回答

0

您missplaced管道符號:

試試這個:

#!/bin/bash 

mysql -u root -password << EOF | 
use runk_prd; 
SELECT user_push_token FROM users WHERE user_push_token <> 'NULL' 
EOF 
while read user_push_token; do 
    echo "pushToken: $user_push_token" 
done