当我运行SQL脚本从MySQL数据库导出数据时,使用命令行,我得到上述错误。 SQL查询在phpMyAdmin中运行时工作正常,但只是从命令行运行时会抛出错误。
这是我正在使用的命令行:
cat my_export | mysql -uxyzuser -pabcpassword mydb > export072911.txt
my_export
中的代码如下:
SELECT CONCAT( custfirstname, ' ', custlastname ) AS fullname, custcompany, \
SPACE( 10 ) AS custtitle, custaddressone, custaddresstwo, custcity, custstate, \
custzip, SPACE( 10 ) AS dummy, custphone, SPACE( 10 ) AS custfax, custemail, \
event_id, SPACE( 10 ) AS ticket1, SPACE( 10 ) AS ticket2, \
SPACE( 10 ) AS ticket3, SPACE( 10 ) AS ticket4, orderdate, b.quantity, \
FROM order_master a \
LEFT JOIN order_detail b ON b.order_master_id = a.id \
LEFT JOIN customer c ON c.email = a.custemail \
WHERE a.orderdate > '2010-12-01'\
AND a.event_id = '30' \
AND a.orderstatus = 'O' \
AND b.litype = 'ITEM' \
AND b.reftag = 'PKG' \
ORDER BY a.orderdate DESC;
答案 0 :(得分:3)
您可以安全地删除所有反斜杠并使用输入重定向而不是管道。如果您将SQL用作shell变量,则需要使用反斜杠,但不能用于管道或重定向。
mysql -uxyzuser -pabcpassword mydb < my_export > export072911.txt
UPDATE 经过对我自己的快速测试后,只要反斜杠被移除,管道看起来就像输入重定向一样。