Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR at line 1: Unknown command '\ '

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;
like image 974
newbie Avatar asked Feb 23 '26 10:02

newbie


1 Answers

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.

like image 136
Michael Berkowski Avatar answered Feb 25 '26 00:02

Michael Berkowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!