使用.php文件生成MySQL转储 [英] Using a .php file to generate a MySQL dump

查看:45
本文介绍了使用.php文件生成MySQL转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我所拥有的信息:

我正在使用MySQL和PHP5在基于Linux的系统上工作.我需要能够从.php文件中生成mysqldump,然后将该转储存储在服务器上我指定的位置的文件中.

I am working with a Linux based system using MySQL and PHP5. I need to be able to generate a mysqldump from within a .php file, and then have that dump be stored in a file on the server in a location I would specify.

因为我是PHP nooblet,所以我希望有人能给我一些帮助,指导或代码,这些可以帮助我完成我所需要的.这必须从Internet远程运行.

As I'm a PHP nooblet, I'd like someone to give me some assistance, guidance, or code, that would do what I require. This would have to be run remotely from the Internet.

推荐答案

您可以使用 exec() 函数来执行外部命令.

You can use the exec() function to execute an external command.

注意:在shell_exec()exec()之间,我会选择第二个,它不会将输出返回到PHP脚本-不需要PHP脚本以字符串的形式获取整个SQL转储:您只需要将其写入文件即可,这可以通过命令本身完成.

Note: between shell_exec() and exec(), I would choose the second one, which doesn't return the output to the PHP script -- no need for the PHP script to get the whole SQL dump as a string : you only need it written to a file, and this can be done by the command itself.


该外部命令将:


That external command will :

  • 使用正确的参数
  • 调用mysqldump
  • 并将输出重定向到文件.

例如:

mysqldump --user=... --password=... --host=... DB_NAME > /path/to/output/file.sql


这意味着您的PHP代码将如下所示:


Which means your PHP code would look like this :

exec('mysqldump --user=... --password=... --host=... DB_NAME > /path/to/output/file.sql');


当然,您可以使用正确的连接信息,将...替换为这些信息.


Of course, up to you to use the right connection information, replacing the ... with those.

这篇关于使用.php文件生成MySQL转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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