2011-07-29 127 views
2

當我運行SQL腳本以將數據從MySQL數據庫中導出時,使用命令行,出現上述錯誤。 在phpMyAdmin中運行時,SQL查詢可以正常工作,但僅在從命令行運行時會引發錯誤。錯誤在第1行:未知命令''

這裏是我使用的命令行:

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; 

回答

3

您可以安全地刪除所有反斜槓和使用輸入重定向,而比管道。如果使用SQL作爲shell變量,而不是管道或重定向,則需要反斜槓。

mysql -uxyzuser -pabcpassword mydb <my_export> export072911.txt 

UPDATE我自己的一個快速測試後,它看起來像管的工作原理一樣好輸入重定向只要反斜槓被除去了。

+0

想想你是如何在命令行上執行此操作的(例如在mysql工具中)。你可以輸入/按enter/type /按回車鍵/ etc,直到你插入命令終止符';'命令行只是取數據。重定向:) – KevinDTimm

+0

酷,這工作。非常感謝Michael和KevinDimim。 – newbie