I’m exporting a roundcube MySQL database using Mysqldump but sadly it fails when I use a long query. How can I escape this so it works?
mysqldump -t –skip-add-drop-table roundcube contacts –where=”select * from contacts where user_id in (select user_id from users where username like ‘%mysite.com%’)” > roundcube_contacts.sql
Running the above gives me this error, so how do I escape the query properly?
mysqldump: Couldn’t execute ‘SELECT /*!40001 SQL_NO_CACHE / /!50084 SQL_NO_FCACHE */ * FROM
contactsWHERE select * from contacts where user_id in (select user_id from users where username like ‘%mysite.com%’)’: 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 ‘select * from contacts where user_id in (select user_id from users where usernam’ at line 1 (1064)
The mysqldump
--whereoption specifies the text to be included in the WHERE clause.You’ve got a whole statement there, and that generates a syntax error,
mysqldump is already writing the
SELECT * FROM roundcube.contacts. The –where option is telling mysqldump to include a WHERE keyword, followed by the text you supply, as part of the statement it generates.You want something more along the lines of:
–where=”user_id in (select user_id from users where username like ‘%mysite.com%’)”
so the generated statement would be…
Also, the database name and table name should follow the options…