mysql dump a list of query to file and restore to another database I have 2 databases. The first one is a production have some data deleted. The 2nd one is a backup so it has everything. I traced the log so I got every records are deleted in production database by the list like this

SELECT * FROM `journal_details` WHERE `journal_details`.`journal_id` = 28679;
SELECT * FROM `journals` WHERE `journals`.`id` = 28679;
SELECT * FROM `journal_details` WHERE `journal_details`.`journal_id` = 29262;
SELECT * FROM `journals` WHERE `journals`.`id` = 29262;


I want to migrate the result of queries above to the production database. How to do it the easy way? I can't restore the whole database due to it will overwrite some other records :(

PS: I tried mysqldump like this but got errors :(

mysqldump -u dk2303  -h 127.0.0.1 -p  rm_production --default-character-set=utf8 --result-file=/home/dk/dump.sql --where="SELECT * FROM journal_details WHERE journal_details.journal_id = 28679; "
mysqldump: [Warning] Using a password on the command line interface can be insecure.
mysqldump: Couldn't execute 'SELECT /*!40001 SQL_NO_CACHE */ * FROM `attachments` WHERE SELECT * FROM journal_details WHERE journal_details.journal_id = 28679; ': 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 journal_details WHERE journal_details.journal_id = 28679' at line 1 (1064)
I think if you're going to use a WHERE clause, you need to specify your table in the mysqldump command. You also just need to include the WHERE clause and not the corresponding SELECT - as per follows:

mysqldump -t -u dk2303 -p my_database journal_details  --where="journal_id = 28679"  



journal_details is your table.  
--h 127.0.0.1 is the default anyway so not necessary  
--default-character-set=utf8 (keep this - may be default also?)  
--result-file=/home/dk/dump.sql (you can keep this also, otherwise just use the &gt; redirect operator)   


See here for more details.