2013-12-19 151 views
5

我想知道所有常見的位置mysqldump。我已經拿出名單如下:mysqldump mac/linux的常見安裝位置

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

通常的mysqldump沒有路徑,所以我想都在看的位置(我來自一個PHP腳本運行此)。

有什麼我失蹤?

+0

您是否嘗試在第一次運行時運行'find/-name mysqldump -type f -perm/u = x',然後將值緩存在文件中? –

+0

我還沒試過。我只是在我的Mac上做了這個,得到了'find:-perm:/ u = x:非法模式字符串' –

+0

看起來像舊版本的find,嘗試-perm/u + x或-perm/444甚至更老的-perm +444 –

回答

6

我無法找到任何其他路徑,除了你在問題中給出的路徑。然而,我想到的一件事是在大多數情況下,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二進制文件的顯式路徑的方法。應該爲你的用例工作:)

+0

謝謝你的提示。這很好。 (我修改了一下,但'which'命令是個好主意。 –