snippetsqlModerate
How to export mysql database based on a where condition
Viewed 0 times
conditionwheredatabasemysqlexportbasedhow
Problem
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.
How to export mysql database based on a where condition from phpMyAdmin or anything.
Solution
Using SQL from the mysql command-line:
or using mysqldump with the --where= option:
Using phpMyAdmin you can execute the query in the GUI & click "export" under the resultset.
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.sqlUsing phpMyAdmin you can execute the query in the GUI & click "export" under the resultset.
Code Snippets
SELECT * from YOURTABLE
WHERE status=0 and id>20
INTO OUTFILE 'yourtable.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';mysqldump -u youruser -p yourdbname yourtablename --where="status=0 and id>20">yourtable.sqlContext
StackExchange Database Administrators Q#15334, answer score: 17
Revisions (0)
No revisions yet.