如何将MySQL数据库连接到Ubuntu上的C
How to connect a MySQL database to C++ on Ubuntu?
我正在尝试在C 中建立一个数据库管理系统,但是我一直在努力工作很多小时,甚至将MySQL连接到我的程序。
我是C 的童话,但我在Java上有经验,与MySQL相关的痛苦从来都不是很痛苦。
我尝试了以下代码的十几个变体,但我仍然没有成功。
如何将MySQL数据库连接到Linux的C ?
目前我的代码看起来像:
#include <iostream>
#include <stdlib.h>
#include <string>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <mysql_driver.h>
using namespace std;
int main() {
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
sql::ConnectOptionsMap connection_properties;
/* Create a connection */
driver = sql::mysql::MySQL_Driver::get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "rootpass");
/* Connect to the MySQL test database */
con->setSchema("test");
delete con;
return 0;
}
,这些是我收到的错误:
错误:‘get_mysql_driver_instance'不是'sql :: mysql :: mysql_driver'的成员 驱动程序= sql :: mysql :: mysql_driver :: get_mysql_driver_instance((;
cmakefiles/superstorage.dir/build.make:62:目标'cmakefiles/superstorage.dir/main.cpp.o'失败的食谱制作[3]:* [CMAKEFIELS/SUPERSTREADOK.DIR/MAIN.CPP.O]错误1cmakefiles/makefile2:67:目标'cmakefiles/superstorage.dir/all'失败的食谱制作[2]: [cmakefiles/superstorage.dir/all]错误2cmakefiles/makefile2:79:目标'cmakefiles/superstorage.dir/rule'失败制作[1]: [cmakefiles/superstorage.dir/规则]错误2makefile:118:目标"超级恒星"的食谱失败制作: * [Superstorage]错误2
这是错误的:
driver = sql::mysql::MySQL_Driver::get_mysql_driver_instance();
应该是:
driver = sql::mysql::get_mysql_driver_instance();
这在用于连接到数据库的旧MySQL C 连接器教程页面中清楚地显示了这一点(尽管8.0文档似乎已删除了所有用法示例 (。
- wxWebView在Ubuntu上的编译问题
- 从ubuntu上的utc时间计算unix时间
- 如何在 ubuntu 上的 php 脚本中获取程序(c,c++,java,python,php)的执行时间和内存使用量?
- gRPC 不为 ubuntu 上的 c++ 生成库
- 如何获得一个使用 XWindows 在 Windows 上的 Ubuntu 上的 Bash 上构建的 C++ 程序?
- Ubuntu上的OpenCv设置
- 如何将MySQL数据库连接到Ubuntu上的C
- Ubuntu上的库ICU不想从Unicode转换为Windows-1251
- 用不同版本的Ubuntu上的GCC编译会产生不同的结果
- 使用Boost Python V1.67和Ubuntu上的CMAKE构建基本C 项目
- 在Windows上与Ubuntu上的C 17对齐
- Ubuntu上的启动ITK/VTK项目中的错误
- 使用Rosmake(Ubuntu上的动力学16.04)建造C 项目
- OPENCV在Ubuntu上的CUDA支持中失败
- 'GLEWContext does not name a type' Ubuntu 上的错误
- 如何在Ubuntu上的G 中编译一个程序,具有多个源文件
- boost :: ubuntu上的系统链接错误
- 在 Eclipse 中调试 Ubuntu 上的C++项目不会在断点处停止
- Ubuntu 上的 Qt+OpenCV 无法运行/调试:无法启动应用程序
- Ubuntu上的分段错误(核心转储)