Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I need to export the data and structure of a table but the data must have a specific condition (WHERE status=0 and id>20).

How to export mysql database based on a where condition from phpMyAdmin or anything.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Using SQL from the mysql command-line:

SELECT * from YOURTABLE
WHERE status=0 and id>20
INTO OUTFILE 'yourtable.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';

or using mysqldump with the --where= option:

mysqldump -u youruser -p yourdbname yourtablename --where="status=0 and id>20">yourtable.sql

Using phpMyAdmin you can execute the query in the GUI & click "export" under the resultset.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.