2014-03-29 4 views
1

또 다른 질문을 실패 이 메시지를 가지고 : 나는 (... MySQL의 -u 루트 -p) 콘솔을 통해 연결을 시도 할 때연결 시도가 실패 MySQL의 연결에 MySQL을 마시고에게

연결 시도가,

반면

실패를, 그것은 작동합니다.

아마도 MySQL 구성에서 중요한 단계를 잊어 버렸을 수 있습니까?

여기 내 코드입니다 :

#include <iostream> 
#include <string> 

#include <Poco/Data/MySQL/MySQLException.h> 
#include <Poco/Data/MySQL/Connector.h> 
#include <Poco/Data/SessionFactory.h> 

using namespace std; 

int main() 
{ 
    Poco::Data::MySQL::Connector::registerConnector(); 
    try 
    { 
     string str = "host=localhost;user=root;password=mypassword;compress=true;auto-reconnect=true"; 
     Poco::Data::Session test(Poco::Data::SessionFactory::instance().create(Poco::Data::MySQL::Connector::KEY, str)); 
    } 
    catch (Poco::Data::MySQL::ConnectionException& e) 
    { 
     cout << e.what() << endl; 
     return -1; 
    } 
    catch(Poco::Data::MySQL::StatementException& e) 
    { 
     cout << e.what() << endl; 
     return -1; 
    } 

    return 0; 
} 

감사합니다!

+0

나는 항상이 버그를 수정했습니다. MySQL을 다시 설치하려고했지만 여전히 작동하지 않습니다. – Alfred

답변

2

ok "호스트"의 "localhost"값이 내 리눅스에서 작동하지 않습니다 (이유를 모르겠습니다). 버그 수정을 위해 문자열을 다음과 같이 변경해야했습니다.

string str = "host=127.0.0.1;user=root;password=mypassword;compress=true;auto-reconnect=true";