我需要备份数据库中的一些选定表。我的 php 页面中有一个表单,当单击表单上的提交按钮时,选定表的备份将以 .sql 或 .sql zip 形式存储到我的计算机中文件。
(例如:如果 db1 是我的数据库名称,table1、table2、table3 是表,则单击表单中的提交按钮,仅备份 tabl1、table2 并将其另存为 .sql 或 .sqlzip 文件在我的计算机)。
如果有人知道解决方案,请在此发帖。
最佳答案
如果您要从 mydb 转储表 t1、t2 和 t3
mysqldump -uYouruser -pYourPassword YourDBName Table1 Table2 Table3 > /PathWhereToStoreBackup/mydb_tables.sql
如果 mydb 中有大量表,并且您想要转储除 t1、t2 和 t3 之外的所有内容,请执行以下操作:
DBTODUMP=mydb
TBLIST=`mysql -u... -p... -AN -e"select group_concat(table_name separator ' ') from information_schema.tables where table_schema='${DBTODUMP}' and table_name not in ('t1','t2','t3')"`
mysqldump -u... -p... ${DBTODUMP} ${TBLIST} > mydb_tables.sql
关于php - 如何使用 php 代码从数据库备份某些特定表并将 .sql 保存到我的计算机中的某个位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21545741/