C++ 连接尝试失败MySQL poco

C++ 连接尝试失败MySQL poco,c++,mysql,mysql-connector,poco-libraries,C++,Mysql,Mysql Connector,Poco Libraries,关于Mysql连接失败的另一个问题: 我正在使用Poco库(1.5.2),我想知道为什么当我尝试打开MySQL连接时,我收到以下消息: 连接尝试失败 然而,当我尝试通过控制台(mysql-u root-p…)进行连接时,它是有效的 也许我忘记了MySQL配置中的一个重要步骤 这是我的密码: #include <iostream> #include <string> #include <Poco/Data/MySQL/MySQLException.h> #in

关于Mysql连接失败的另一个问题:

我正在使用Poco库(1.5.2),我想知道为什么当我尝试打开MySQL连接时,我收到以下消息:

连接尝试失败

然而,当我尝试通过控制台(mysql-u root-p…)进行连接时,它是有效的

也许我忘记了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;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
Poco::Data::MySQL::Connector::registerConnector();
尝试
{
string str=“host=localhost;user=root;password=mypassword;compress=true;auto-reconnect=true”;
Poco::Data::Session测试(Poco::Data::SessionFactory::instance().create(Poco::Data::MySQL::Connector::KEY,str));
}
catch(Poco::Data::MySQL::ConnectionException&e)
{
cout好的问题是“host”的“localhost”值在我的linux上不起作用(我不知道为什么)。为了修复错误,我必须将字符串更改为:

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

我一直都有这个bug。我试图重新安装MySQL,但仍然不起作用:(