php - mysql 从相互关联的特定表中转储

标签 php mysql

我的 MySQL 数据库中有 2 个表。

我需要将两个表输出到 SQL 转储文件。(创建脚本)

但是,我可能只会转储某些行。(例如,where column = value)。

第一个表没问题。

但是,第二个表可能只会转储行,例如列 = 第一个结果集中存在的值。

我想使用 mysqldump,但我不认为它适用于这种类型的查询,除非我进行某种连接或联合?

我还可以使用 PHP 并在循环遍历行的同时创建文件,但我认为这不是最有效的方法。

任何建议或帮助将不胜感激!

最佳答案

谢谢@MarcB为了回答这个问题,它 100% 有效。我发布这个是为了遵循堆栈溢出的回答规则,同时也是为了展示我最终使用的内容。

所以这是我在 bash 脚本中运行的 2 个 mysqldump 命令:(我用“x”替换了一些私有(private)数据)

#!/bin/bash

#dump the first table
mysqldump -h xxx.xxx.xxx.xxx -u xxxxx -pxxxxx --where="name='value'" databasename table1 > /home/xxxxx/xxxxx/table1.sql

#dump the second table that relates to the first one
mysqldump -h xxx.xxx.xxx.xxx -u xxxxx -pxxxxx --lock-all-tables --where="field_id in (select anotherfield_id from table1 where name='value')" databasename table2 > /home/xxxxx/xxxxx/table2.sql

关于php - mysql 从相互关联的特定表中转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30440953/

相关文章:

php - 多个带有值的仪表

mysql - 登录laravel时如何检查表company的字段comp_status?

mysql - mdb-export 更改每一行的 GUID

jquery - 为什么我的第二个下拉菜单没有被填充?

php - 在 Codeigniter 电子邮件库中调用发送方法时出错

php - 取消链接/file_exists 和文件未找到

php - DataTables:#example 工作但 #datatable 在进行 AJAX 调用时不工作

mysql - 从其他表中查找具有所有值的所有 ID

php - PHPUnit 是否有一些内置的递归数组比较功能?

php:创建自动数据库分片逻辑?