I am trying to know all the common locations for mysqldump
. The list I have come up with is as follows:
'/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)
Are there any that I am missing?
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.
And, therefore, you can combine the two logics to have the location of the mysqldump
binary, in most cases, like this:
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With