2013-12-19 3 views
5

mysqldump에 대한 모든 일반적인 위치를 알고 싶습니다. 다음과 같이 내가 함께 온 목록은 다음과 같습니다mac/linux 용 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 스크립트에서이 작업을 실행하고 있습니다).

누락 된 항목이 있습니까?

+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); 
} 

지금, 당신은 당신의 목적을 위해 위의 기능을 사용할 수 있습니다. 위의 함수가 오류를 throw하면 사용자가 mysqldump 바이너리에 명시 적 경로를 수동으로 제공 할 수있는 방법을 제공하십시오. 당신의 유스 케이스를 위해 일해야한다 :)

+0

팁 주셔서 감사합니다. 이것은 훌륭하게 작동했습니다. (조금 수정했지만'which' 명령은 좋은 생각이었습니다. –