如何根据where条件导出mysql数据库


12

我需要导出表的数据和结构,但是数据必须具有特定条件(WHERE status = 0和id> 20)。

如何从phpMyAdmin或其他条件中基于where条件导出mysql数据库。

Answers:


11

从mysql命令行使用SQL:

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

或将mysqldump与--where =选项一起使用:

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

使用phpMyAdmin,您可以在GUI中执行查询,然后在结果集下单击“导出”。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.