C++/MySQL - 通过主机地址访问数据库时'Unknown MySQL server host';没有 IP
C++/MySQL - 'Unknown MySQL server host' when accessing database via host address; Don't have an IP
我在1and1包中设置了一个数据库,我想在c++应用程序中连接到它。它在PHP中运行得很好。
问题是,我没有数据库的实际IP,我只有主机地址和登录详细信息:
主机名:db12345678.db.1and1.com
用户名:dbo12345678
密码:mypassword
我使用的是MySQL C++连接器1.1.4。以下是我的测试代码:
#include <Windows.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <iostream>
#pragma comment(lib,"mysqlcppconn.lib")
int main(int argc,char *argv[])
{
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
driver = get_driver_instance();
con = driver->connect(sql::SQLString("db12345678.db.1and1.com"),sql::SQLString("dbo12345678"),sql::SQLString("mypassword"));
con->setSchema("test");
}
catch(sql::SQLException &e)
{
std::cout<<"Exception: "<<e.what()<<std::endl;
}
while(true);
return 0;
}
使用主机地址,我得到以下输出:
Exception: Unknown MySQL server host 'db12345678.db.1and1.com' (0)
我也试过"tcp://db12345678.db.1and1.com","tcp://db12345678.db.1and1.com:3306","db12345678.db.1and1.com:3306",错误消息不同,但最终结果相同。
我试过ping主机并通过traceroute获取IP,但这不起作用。
我还能尝试什么?
今天我遇到MySQL C++连接器的wierd问题,它不接受我的主机。。
这就是我工作的方式:
sql::ConnectOptionsMap connection_properties;
try {
sql::Statement *stmt;
connection_properties ["hostName"] = std::string("host.com");
connection_properties ["userName"] = std::string("dbuser");
connection_properties ["password"] = std::string("dbpass");
connection_properties ["schema"] = std::string("dbname");
connection_properties ["OPT_RECONNECT"] = true;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect(connection_properties);
} catch (sql::SQLException &e) {
std::cout << "# ERR: SQLException in " << __FILE__;
std::cout << "# ERR: " << e.what();
std::cout << " (MySQL error code: " << e.getErrorCode();
std::cout << ", SQLState: " << e.getSQLState() << " )" << std::endl;
}
相关文章:
- C++MySQL C api用户输入行
- "unknown ca"自生成的 CA、证书和客户端/服务器
- 使用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 联接
- 如何在MySQL Connector/C++ 8.0中使用DATETIME?
- 无法使用 aarch64-unknown-nto-qnx7.0.0-g++-5.4.0 编译器交叉编译 QNX 平台的
- Postgres vs MySQL:命令不同步;.
- FindPOCO CMAKE 脚本无法找到 MYSQL::client
- C++/MySQL - 通过主机地址访问数据库时'Unknown MySQL server host';没有 IP