简体   繁体   English

为什么在 php 中进行数据库转储时需要提供完整的 mysqldump 路径

[英]Why should I need to give the full mysqldump path when doing a database dump in php

I am trying to create a mysql database dump in a php class.我正在尝试在 php 类中创建一个 mysql 数据库转储。

I am executing the following code but only an empty dump file will create.我正在执行以下代码,但只会创建一个空的转储文件。 But the same command works fine when I execute it in the command line.但是当我在命令行中执行它时,相同的命令工作正常。

$script = 'mysqldump -h ' . DB_HOST . ' -u ' . DB_USER . ' -p' . DB_PASSWORD . ' ' . DB_NAME . ' > ' . DB_DUMP_PATH . 'mysql-db-dump-' . date('Y-m-d') . '.sql';
exec($script);

But when I give the full path of mysqldump, the dump file create correctly.但是当我给出 mysqldump 的完整路径时,转储文件会正确创建。

$script = '/usr/local/mysql/bin/mysqldump -h ' . DB_HOST . ' -u ' . DB_USER . ' -p' . DB_PASSWORD . ' ' . DB_NAME . ' > ' . DB_DUMP_PATH . 'mysql-db-dump-' . date('Y-m-d') . '.sql';
exec($script);

But I saw most of the tutorials, they just use mysqldump command.但是我看了大部分教程,他们只是使用 mysqldump 命令。 Not the full path.不是完整路径。 What is the reason behind this?这背后的原因是什么? I am planing to use this in both unix and windows environment.我打算在 unix 和 windows 环境中使用它。

Is it possible to get the mysqldump path in php for both environments?是否可以在 php 中获取两种环境的 mysqldump 路径?

您可以通过将mysqldumpmysql命令从/usr/local/mysql/bin/复制到/usr/bin/路径来避免路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM