红联Linux门户
Linux帮助

ubuntu11.04 安装mysql++注意事项

发布时间:2012-01-17 09:39:03来源:红联作者:haolifengwang
即使获得来《葵花宝典》也未必能炼成“东方不败”,还需要努力和钻研!

1.软件环境ubuntu10.10

2. 安装mysql -- sudo apt-get install mysqlserver

3. 安装 libmysqlclient15-dev -- sudo apt-get install libmysqlclient15-dev

(如果提示没有安装包,可以用sudo apt-get install update和sudo apt-get install upgrade进行更新和升级,如果没有网络看来很难学习ubuntu)

4 下载mysql++ --

http://tangentsoft.net/mysql++/releases/mysql++-3.0.9.tar.gz

5 tar -vxf mysql++-3.0.9.tar.gz

6 cd mysql++-3.0.9

7. ./configure --prefix=/usr

8. make 第一次可能失败,会提示:./lib/refcounted.h:258:2: 错误: ‘size_t’不是一个类型名
./lib/refcounted.h: 在构造函数‘mysqlpp::RefCountedPointer::RefCountedPointer()’中:

解决方法:打开./lib/refcounted.h,添加#include 和using namespace std;

9.重新编译make

10. sudo make install

11. 安装完毕。

12 测试 代码

#include
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
// Get database access parameters from command line
const char* db = 0, *server = 0, *user = 0, *pass = "";

db = "school";
server = "127.0.0.1";
user = "root";
pass = "hlf";
// Connect to the sample database.
mysqlpp::Connection conn(false);
if (conn.connect(db, server, user, pass)) {
// Retrieve a subset of the sample stock table set up by resetdb
// and display it.
mysqlpp::Query query = conn.query("select * from student");
if (mysqlpp::StoreQueryResult res = query.store()) {
cout << "We have:" << endl;
mysqlpp::StoreQueryResult::const_iterator it;
for (it = res.begin(); it != res.end(); ++it) {
mysqlpp::Row row = *it;
cout << '\t' << row[0] << endl;
}
}
else {
cerr << "Failed to get item list: " << query.error() << endl;
return 1;
}

return 0;
}
else {
cerr << "DB connection failed: " << conn.error() << endl;
return 1;
}
}

13 makefile

tsql:tsql.cpp
g++ -o tsql tsql.cpp -I/usr/include/mysql -I/usr/include/mysql++ -L/usr/lib -lmysqlpp

注意,一定要有lmysqlpp,该句是为了使用库libmysqlpp.a
文章评论

共有 45 条评论

  1. loveline 于 2014-10-16 17:55:38发表:

    Thanks for share

  2. sammas1025 于 2014-10-05 16:17:16发表:

    谢谢分享

  3. mutou1991 于 2014-09-25 17:24:38发表:

    楼主说的好

  4. qxfsy 于 2014-08-09 15:21:06发表:

    了解哈!

  5. william2011 于 2014-07-31 12:23:11发表:

    谢谢分享

  6. markvenus 于 2014-06-13 11:32:26发表:

    我是新手,我要学习

  7. 黄绍凯 于 2014-06-09 14:01:30发表:

    好啊

  8. 执着追求爱 于 2014-06-07 23:39:47发表:

    很有用

  9. 执着追求爱 于 2014-06-07 23:39:28发表:

    不错

  10. senke1 于 2014-01-14 15:06:47发表:

    (e:e2s受教了

  11. Jack561 于 2014-01-13 15:20:36发表:

    谢谢分享

  12. idlerinwind 于 2013-09-30 11:45:53发表:

    努力学习Linux

  13. jyhll123 于 2013-07-25 21:29:43发表:

    受教

  14. bnmluo 于 2012-12-14 17:21:33发表:

    来学习学习

  15. 于 2012-12-12 10:29:59发表:

    学习了

  16. 于 2012-12-12 10:29:45发表:

    学习了,

  17. jdhongtao 于 2012-12-12 09:24:42发表:

    多谢,顶起来

  18. 醉尘风 于 2012-12-11 14:31:33发表:

    学习

  19. gky2009514 于 2012-12-07 12:51:26发表:

    新手完成任务,求下书籍~

  20. huangjie540 于 2012-11-28 21:18:32发表:

    顶顶顶顶顶顶顶顶顶顶顶:0wpoi2。谢谢楼主额

  21. yiiy88 于 2012-11-28 18:17:50发表:

    新人一枚 不会安装任何软件。

  22. ouyangcp 于 2012-10-08 15:04:00发表:

    感?您的教?分享!

  23. 寂寞弯刀 于 2012-10-05 00:27:19发表:

    学习了!

  24. jiangjinta 于 2012-06-24 13:52:31发表:

    境界太高,有点像天书:0)1

  25. jiangjinta 于 2012-06-24 13:22:05发表:

    感觉想在看天书一样啊(5ty(
    努力,加油

  26. liuyanqiu0807 于 2012-06-14 17:12:54发表:

    感谢楼主!

  27. fcyyy 于 2012-06-04 12:16:47发表:

    qwqqq

  28. Lone_Arena 于 2012-05-09 11:06:47发表:

    :0w5ty(1

  29. larmbr 于 2012-05-04 14:56:35发表:

    感谢分享,学习了,谢谢!!!

  30. 于 2012-04-18 15:45:36发表:

    顶啊

  31. tan19880105 于 2012-04-09 11:11:48发表:

    我是新手

  32. lunan_gz 于 2012-04-09 10:48:40发表:

    顶

  33. toby_lund 于 2012-04-02 22:18:07发表:

    楼主辛苦了

  34. fate3008 于 2012-03-30 10:34:08发表:

    :0)1

  35. zyzhang12 于 2012-03-07 03:23:52发表:

    暂时未用

  36. linuxian 于 2012-03-01 20:06:49发表:

    顶楼主

  37. liulanghanzi 于 2012-02-20 16:43:06发表:

    楼主说得很仔细

  38. 君君兮兮 于 2012-02-17 21:43:54发表:

    要是有个视频讲解就完美了。

  39. Lee2012 于 2012-02-11 08:32:36发表:

    :0)1

  40. frankhht 于 2012-01-29 20:24:46发表:

    顶