• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Linux下MySQL C++连接操作

mysql 搞代码 4年前 (2022-01-09) 23次浏览 已收录 0个评论

1,客户端需要安装mysql-cl本文来源gaodai#ma#com搞@@代~&码*网/ient包,安装完后有我们需要的库文件;2,然后安装mysql-dev包,安装完后有我们需要的mysql.h文件;3,作

1,客户端需要安装mysql-client包,安装完后有我们需要的库文件;

2,然后安装mysql-dev包,安装完后有我们需要的mysql.h文件;

3,作为客户端只需要安装这两个包就可以了:

以下是简单的测试代码:
#include
#include
int main()
{
/*declare structures and variables */
MYSQL mysql;
MYSQL_RES *result;
MYSQL_ROW row;
//initialize MYSQL structure
mysql_init(&mysql);
//connect to database
// mysql_real_connect(&mysql,”localhost”,”root”,”nriet”,”test”,0,NULL,0);
mysql_real_connect(&mysql,”192.168.13.27″,”root”,”nriet”,”nriet”,0,NULL,0);
//execute query
mysql_query(&mysql,”select * from test”);
//get result set
result=mysql_store_result(&mysql);
//process result set
while((row=mysql_fetch_row(result)))
{
fprintf(stdout,”%s – %s\n”,row[0],row[1]);
}
//mysql_query(&mysql,”insert into test values(3,’a’)”);
//clean up
mysql_free_result(result);
mysql_close(&mysql);
}

4,在“GCC C++ Linker”下的“Libraries”:

libraries(-l):mysqlclient
Libraries search path(-L):/usr/lib/mysql
然后 就可以 大功告成了 !!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Linux下MySQL C++连接操作
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址