mac mysql mysqldump_php – mysqldump mac / linux的常用安装位置

我想知道mysqldump的所有常见位置.我提出的清单如下:

'/usr/bin/mysqldump', //Linux

'/usr/local/mysql/bin/mysqldump', //Mac OS X

'/usr/local/bin/mysqldump', //Linux

'/usr/mysql/bin/mysqldump'; //Linux

通常mysqldump不在路径中,所以我试图让所有的位置都可以查看.(我是从php脚本运行的)

有什么我想念的吗?

解决方法:

除了你在问题中给出的那些之外,我找不到任何其他路径.但是,我想到的一件事是,在大多数情况下,mysqldump应该与mysql二进制文件位于同一目录中.现在,在大多数情况下,mysql命令也将在路径中.

因此,在大多数情况下,您可以将两个逻辑组合在一起以获得mysqldump二进制文件的位置,如下所示:

function detect_mysqldump_location() {

// 1st: use mysqldump location from `which` command.

$mysqldump = `which mysqldump`;

if (is_executable($mysqldump)) return $mysqldump;

// 2nd: try to detect the path using `which` for `mysql` command.

$mysqldump = dirname(`which mysql`) . "/mysqldump";

if (is_executable($mysqldump)) return $mysqldump;

// 3rd: detect the path from the available paths.

// you can add additional paths you come across, in future, here.

$available = array(

'/usr/bin/mysqldump', // Linux

'/usr/local/mysql/bin/mysqldump', //Mac OS X

'/usr/local/bin/mysqldump', //Linux

'/usr/mysql/bin/mysqldump' //Linux

);

foreach($available as $apath) {

if (is_executable($apath)) return $apath;

}

// 4th: auto detection has failed!

// lets, throw an exception, and ask the user to provide the path instead, manually.

$message = "Path to \"mysqldump\" binary could not be detected!\n"

$message .= "Please, specify it inside the configuration file provided!"

throw new RuntimeException($message);

}

现在,您可以将上述功能用于您的目的.并且,如果上述函数抛出错误,则为用户提供手动提供mysqldump二进制的显式路径的方法.应该适用于您的用例:)

标签:php,mysqldump

来源: https://codeday.me/bug/20190517/1120804.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值