Export SELECT WHERE query MYSQL into .sql files using mysqldump


You will need this scripts if you have two databases and want to synchronize each other.

First, we need to export SELECT QUERY into .sql files by:

1
mysqldump –databases DATABASE_NAME –tables TABLE_NAME –where=’YOUR_COLUMN_NAME IN ("SOME-ID", "SOME-ID")’ -u root -pYOUR_PASSWORD > data.sql

The last thing, you need to edit this “sql” files and change the DATABASE_NAME into your another DATABASE_NAME that will imported.
Then you can import this into your ANOTHER_DATABASE by:

1
mysql -u root -pYOUR_PASSWORD DATABASE_NAME –database=YOUR_ANOTHER_DATABASE < data.sql

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.