mysqldump mac / linux的常用安装位置

时间:2021-11-14 01:32:18

I am trying to know all the common locations for mysqldump. The list I have come up with is as follows:

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

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

Often mysqldump isn't in the path, so I am trying to have all the locations to look in. (I am running this from a php script)

通常mysqldump不在路径中,所以我试图查看所有位置。(我从php脚本运行它)

Are there any that I am missing?

有什么我想念的吗?

1 个解决方案

#1


6  

I was unable to find any other paths apart from the ones you have given in your question. However, one thing that does come in my mind is that mysqldump should, in most cases, be in the same directory as the mysql binary. Now, the mysql command will be in the path, in most cases, as well.

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

And, therefore, you can combine the two logics to have the location of the mysqldump binary, in most cases, like this:

因此,在大多数情况下,您可以将两个逻辑组合在一起以获得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);
}

Now, you can use the above function for your purposes. And, provide a way for the user to provide the explicit path to mysqldump binary manually, if the above function throws an error. Should work for your use cases :)

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

#1


6  

I was unable to find any other paths apart from the ones you have given in your question. However, one thing that does come in my mind is that mysqldump should, in most cases, be in the same directory as the mysql binary. Now, the mysql command will be in the path, in most cases, as well.

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

And, therefore, you can combine the two logics to have the location of the mysqldump binary, in most cases, like this:

因此,在大多数情况下,您可以将两个逻辑组合在一起以获得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);
}

Now, you can use the above function for your purposes. And, provide a way for the user to provide the explicit path to mysqldump binary manually, if the above function throws an error. Should work for your use cases :)

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