Linux下安装使用mysql connector(C++)
2015-12-08 10:51
337 查看
http://blog.csdn.net/cscmaker/article/details/7468374
(1)使用C++版本的mysql connector首先需要安装和编译boost库。
可以在boost官网上下载源文件,自己进行编译。也可以直接使用命令下载和编译,具体命令为:
apt-get install libboost-dev libboost-dbg libboost-doc bcp libboost-*
(2)然后需要下载mysql connector的头文件和库,
下载地址为:
http://www.mysql.com/downloads/connector/cpp/
(3)下载以后将文件进行解压
然后将文件夹中的include中的文件和lib中的文件分别拷到/usr/include和/usr/lib中。
(4)使用代码测试(testmysql.cpp):
[cpp] view
plaincopy
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
using namespace std;
#include <mysql_connection.h>
#include <mysql_driver.h>
#include <cppconn/driver.h>
using namespace sql;
#define DBHOST "tcp://127.0.0.1:3306"
#define USER "root"
#define PASSWORD "your password here"
int main() {
Driver *driver;
Connection *conn;
driver = get_driver_instance();
conn = driver->connect(DBHOST, USER, PASSWORD);
conn->setAutoCommit(0);
cout<<"DataBase connection autocommit mode = "<<conn->getAutoCommit()<<endl;
delete conn;
driver = NULL;
conn = NULL;
return 0;
}
然后对该文件进行编译:g++ -o testmysql -lmysqlcppconn testmysql.cpp
注意编译时不要忘了使用-lmysqlcppconn。
(1)使用C++版本的mysql connector首先需要安装和编译boost库。
可以在boost官网上下载源文件,自己进行编译。也可以直接使用命令下载和编译,具体命令为:
apt-get install libboost-dev libboost-dbg libboost-doc bcp libboost-*
(2)然后需要下载mysql connector的头文件和库,
下载地址为:
http://www.mysql.com/downloads/connector/cpp/
(3)下载以后将文件进行解压
然后将文件夹中的include中的文件和lib中的文件分别拷到/usr/include和/usr/lib中。
(4)使用代码测试(testmysql.cpp):
[cpp] view
plaincopy
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
using namespace std;
#include <mysql_connection.h>
#include <mysql_driver.h>
#include <cppconn/driver.h>
using namespace sql;
#define DBHOST "tcp://127.0.0.1:3306"
#define USER "root"
#define PASSWORD "your password here"
int main() {
Driver *driver;
Connection *conn;
driver = get_driver_instance();
conn = driver->connect(DBHOST, USER, PASSWORD);
conn->setAutoCommit(0);
cout<<"DataBase connection autocommit mode = "<<conn->getAutoCommit()<<endl;
delete conn;
driver = NULL;
conn = NULL;
return 0;
}
然后对该文件进行编译:g++ -o testmysql -lmysqlcppconn testmysql.cpp
注意编译时不要忘了使用-lmysqlcppconn。
相关文章推荐
- Linux平台swift语言开发学习环境搭建
- Linux 强大的nohup(后台进程执行)
- Linux 强大的nohup(后台进程执行)
- linux系统监控工具汇总及几个小脚本 , 系统初始化脚本
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑
- Linux学习笔记--6.vim文本编辑