连接尝试失败 MySQL poco.
Connection attempt failed MySQL poco
关于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;
}
谢谢!!
好的,
问题是"host"的"localhost"值在我的Linux上不起作用(我不知道为什么)。为了修复错误,我不得不将字符串更改为:
string str = "host=127.0.0.1;user=root;password=mypassword;compress=true;auto-reconnect=true";
相关文章:
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- C++MySQL C api用户输入行
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 使用mysql c++连接器的未定义引用
- 无法在C++中建立与MySQL数据库的连接
- mysql C++ connector [mysql-connector-c++-8.0.19-linux-glibc2
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- Poco FindMySql.cmake 无法找到 MySQL 源代码
- MySQL C++连接器链接错误
- 配置:错误:找不到 MySQL 包含目录
- 在装有 CLion 的 Mac 上使用 C++ 连接到 MySQL 数据库时出现问题
- C++MySQL连接器没有utf8
- Qt5 从 MySQL 数据库中选择数据
- Arch Linux.AUR 包 mysql 不能用 makepkg 构建.错误:构建 () 中出现故障
- 在 MySQL/Connector C++中使用 SQL 联接
- 像 POCO 这样的C++图书馆如何访问网络?
- Poco::Net::FTPClientSession 在 open() 方法上挂起 129 秒,如果 ftp 主机不存
- 用于构建 POCO 库的 mysql 连接器
- 连接尝试失败 MySQL poco.
- 使用Poco连接MySQL失败