我想制作一个数据库的转储文件,但我想从数据库中得到的只是与特定值关联的行。例如,我想为所有包含 23e4r
的 organization_id
行的表创建一个转储文件。有没有办法做到这一点?
最佳答案
mysqldump 有一个 --where
选项,它允许您指定 WHERE
子句,就像您正在编写查询一样,例如:
mysqldump -u<user> -p<password> --where="organization_id=23e4r" <database> <table> > dumpfile.sql
如果您想转储符合该条件的多个表的结果,其:
for T in table1 table2 table3; do mysqldump -u<user> -p<password> --where="organization_id=23e4r" <database> $T >> dumpfile.sql;done
假设您使用的是 bash shell 或等价物
关于MySQL 在数据库中转储特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29449196/