php - mac/linux 的 mysqldump 常见安装位置

标签 php mysqldump

我想知道 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/

相关文章:

php - 从查询中排除当前帖子的缩略图

php - 检查用户登录ajax页面是否更改

php - 当条件满足时跳出 if 语句和循环

javascript - 如何根据 PHP 响应隐藏/显示 HTML 元素?

mysql - 从 mysqldump 创建的 SQL 恢复后出现错误 1465 "Triggers can not be created on system tables"

mysql - mysqldump 是否保留索引信息?

mysql 从转储 : ERROR 1452 (23000) at line 13: Cannot add or update a child row: a foreign key constraint fails 加载

MySQL 导入显示成功但未生成表

mysql - 如何将 MySQL 迁移到 MySQL 5 数据库

php - 想要在查询中显示数据库中包含多个引号的图像