技术博客

c/c++/python/linux
随笔 - 4, 文章 - 0, 评论 - 2, 引用 - 0
数据加载中……

centos 6.5 x86-64 下编译安装mysql_connector_c++

### 安装依赖

    [chenjunjun@localhost ~]$ su -
    Password:
    [root@localhost ~]# yum install wget cmake gcc-c++ boost-devel mysql-devel
    [root@localhost ~]# exit
    logout
    [chenjunjun@localhost ~]$

### 编译安装mysql-connector-c++

    [chenjunjun@localhost ~]$ wget http://dev.mysql.com/get/Downloads/Connector-C++/mysql-connector-c++-1.1.4.tar.gz
    [chenjunjun@localhost ~]$ tar zxvf mysql-connector-c++-1.1.4.tar.gz
    [chenjunjun@localhost ~]$ cd mysql-connector-c++-1.1.4
    [chenjunjun@localhost mysql-connector-c++-1.1.4]$ mkdir build
    [chenjunjun@localhost mysql-connector-c++-1.1.4]$ cd  build
    [chenjunjun@localhost build]$ cmake -DCMAKE_INSTALL_PREFIX=/home/chenjunjun/usr/mysql_connect_c++/ -DMYSQL_LIB=/usr/lib64/mysql/libmysqlclient.so ..
    [chenjunjun@localhost build]$ make
    [chenjunjun@localhost build]$ vim cppconn/cmake_install.cmake
             38     "/home/chenjunjun/mysql-connector-c++-1.1.4/cppconn/config.h"
            ==修改为==>
             38     "/home/chenjunjun/mysql-connector-c++-1.1.4/build/cppconn/config.h"
    [chenjunjun@localhost build]$ make install
    [chenjunjun@localhost build]$ cd
    [chenjunjun@localhost ~]$

### 设置

    [chenjunjun@localhost ~]$ echo "export LD_LIBRARY_PATH=~/usr/mysql_connect_c++/lib/" >> ~/.bashrc
    [chenjunjun@localhost ~]$ . ./.bashrc

### 测试

    [chenjunjun@localhost ~]$ vi test.cc

        #include <iostream>
        #include <string>
        #include <mysql_connection.h>
        #include <mysql_driver.h>
    
        using namespace std;
        using namespace sql;
    
        int main(){
            Driver* driver;
            Connection* conn;
            driver = get_driver_instance();
            conn = driver->connect("数据库地址", "用户名", "用户密码");
            conn->setAutoCommit(1);
            cout << "DataBase connection autocommit mode = " << conn->getAutoCommit() << endl;
            delete conn;
            driver = NULL;
            conn = NULL;
    
            return 0;
        }
    
    [chenjunjun@localhost ~]$ g++ test.cc -I ~/usr/mysql_connect_c++/include -L ~/usr/mysql_connect_c++/lib -l mysqlcppconn -o test
    [chenjunjun@localhost ~]$ ./test
    DataBase connection autocommit mode = 1
    [chenjunjun@localhost ~]$

posted on 2014-08-12 17:01 chenjunjun 阅读(4438) 评论(0)  编辑 收藏 引用 所属分类: linuxc/c++mysql


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理