第 1 行错误:未知命令 '\ '

发布于 2024-11-27 04:37:54 字数 937 浏览 1 评论 0原文

当我使用命令行运行 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;

When I run the SQL script to export data out of MySQL database, using command line, I get the above error.
The SQL query works fine when run in phpMyAdmin, but just when run from command line throws an error.

Here is the command line I am using:

cat my_export | mysql -uxyzuser -pabcpassword mydb > export072911.txt

The code in my_export is as follows:

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝颜夕 2024-12-04 04:37:54

您可以安全地删除所有反斜杠并使用输入重定向而不是管道。如果您将 SQL 作为 shell 变量使用,但不需要管道或重定向,则需要反斜杠。

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

更新 经过我自己的快速测试,看起来只要删除反斜杠,管道就可以像输入重定向一样工作。

You can safely delete all the backslashes and use input redirection rather than piping. The backslashes are needed if you are working with the SQL as a shell variable, but not for piping or redirection.

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

UPDATE After a quick test of my own, it looks like the pipe works just as well as input redirection as long as the backslashes are removed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文