2016-11-09 144 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