1
另一个问题是一个MySQL连接上失败:连接尝试失败,MySQL的POCO
我使用波苏库(1.5.2),我想知道为什么,当我尝试打开一个MySQL连接,我得到这个消息:
连接尝试失败
然而,当我尝试通过控制台连接(MySQL的ü根 - 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;
}
谢谢!!
我总是这个bug。我试图重新安装MySQL,但它仍然无法工作:( – Alfred