我想知道 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 - mac/linux 的 mysqldump 常见安装位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20671735/