Here's the information I have:

以下是我的信息:

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.

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

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.

由于我是一个PHP nooblet,我希望有人能给我一些帮助、指导或代码,这将会满足我的要求。这将不得不在互联网上远程运行。

16 个解决方案

#1


135

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

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

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.

注意:shell_exec()和exec()之间,我会选择第二个,不返回输出的PHP脚本,不需要PHP脚本得到整个SQL转储为字符串:你只需要写入一个文件,这可以通过命令本身。


That external command will :

外部命令将:

  • be a call to mysqldump, with the right parameters,
  • 用正确的参数调用mysqldump,
  • and redirect the output to a file.
  • 并将输出重定向到文件。

For example :

例如:

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


Which means your PHP code would look like this :

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

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.

当然,您可以使用正确的连接信息,替换……与那些。

更多相关文章

  1. PHP上传文件 Error 6解决方法
  2. thinkPHP5下扩展encryptedData解密算法文件的注意事项
  3. 如何加载json文件?
  4. 使用AJAX将数据发送到.php文件,如何从中获取数据?
  5. 使用javascript将文件输入到php文件
  6. 迭代文件夹中的CSV文件,并使用PHP将数据加载到MySQL中
  7. 用于cdn集成的文件类型的域更改正则表达式
  8. PHP基础 文件流
  9. 教你如何利用php.exe运行php文件

随机推荐

  1. 使用多状态按钮ToggleButton
  2. Android代码速查,写给新手的朋友们
  3. Android Binder 系统级使用demo
  4. Android性能优化案例研究
  5. Android 强制设置横屏或竖屏
  6. android4.0创建AVD后,打开虚拟机黑屏问题
  7. Android下Speex库除0错误(SIGFPE)排除
  8. and 使用以及添加一个自己的mime type在C
  9. 《H5 App开发》判断当前环境是Android还
  10. Android构建报错:Android resource linkin