仅用php备份和还原mysql转储的最佳方法是什么? [英] What would be the best way to backup and restore mysql dumps with just php?

查看:104
本文介绍了仅用php备份和还原mysql转储的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您是如何从控制台执行此操作的,并且我知道您可以使用php执行控制台命令,但是有一种方法可以递归地将数据库转储到文件中,然后再从该文件中还原它,只需使用PHP的?我希望它能够在Windows和Nix服务器上工作.

I know how you do it from the console, and I know you can execute console commands with php, but would there be a way to recursively dump a database into a file, and then restore it from that file later, just using php? I want it to be able to work on windows and nix servers.

我猜想它将需要遍历表和行,但是我如何获得这些列表和行呢?还是可以做到?如果db大小合适,似乎会占用大量内存.有想法吗?

I am guessing it would need to loop through the tables and rows but how would I get a list of those? Or can it even be done? Seems like it would take a massive amount of memory if db was a good size. Thoughts?

推荐答案

mysql_query("SELECT * INTO OUTFILE 'sql/backup.sql' FROM my_table");
mysql_query("LOAD DATA INFILE 'sql/backup.sql' INTO TABLE my_table");

这篇关于仅用php备份和还原mysql转储的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆