﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-技术博客-随笔分类-linux</title><link>http://www.cppblog.com/chenjunjun/category/20950.html</link><description>c/c++/python/linux</description><language>zh-cn</language><lastBuildDate>Tue, 12 Aug 2014 10:17:09 GMT</lastBuildDate><pubDate>Tue, 12 Aug 2014 10:17:09 GMT</pubDate><ttl>60</ttl><item><title>centos 6.5 x86-64 下编译安装mysql_connector_c++</title><link>http://www.cppblog.com/chenjunjun/archive/2014/08/12/207986.html</link><dc:creator>chenjunjun</dc:creator><author>chenjunjun</author><pubDate>Tue, 12 Aug 2014 09:01:00 GMT</pubDate><guid>http://www.cppblog.com/chenjunjun/archive/2014/08/12/207986.html</guid><wfw:comment>http://www.cppblog.com/chenjunjun/comments/207986.html</wfw:comment><comments>http://www.cppblog.com/chenjunjun/archive/2014/08/12/207986.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/chenjunjun/comments/commentRss/207986.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/chenjunjun/services/trackbacks/207986.html</trackback:ping><description><![CDATA[### 安装依赖<br /><div><br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$ su -<br />&nbsp;&nbsp; &nbsp;Password:<br />&nbsp;&nbsp; &nbsp;[root@localhost ~]# yum install wget cmake gcc-c++ boost-devel mysql-devel<br />&nbsp;&nbsp; &nbsp;[root@localhost ~]# exit<br />&nbsp;&nbsp; &nbsp;logout<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$<br /><br />### 编译安装mysql-connector-c++<br /><br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$ wget http://dev.mysql.com/get/Downloads/Connector-C++/mysql-connector-c++-1.1.4.tar.gz<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$ tar zxvf mysql-connector-c++-1.1.4.tar.gz<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$ cd mysql-connector-c++-1.1.4<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost mysql-connector-c++-1.1.4]$ mkdir build<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost mysql-connector-c++-1.1.4]$ cd&nbsp; build<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost build]$ cmake -DCMAKE_INSTALL_PREFIX=/home/chenjunjun/usr/mysql_connect_c++/ -DMYSQL_LIB=/usr/lib64/mysql/libmysqlclient.so ..<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost build]$ make <br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost build]$ vim cppconn/cmake_install.cmake<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 38&nbsp;&nbsp;&nbsp;&nbsp; "/home/chenjunjun/mysql-connector-c++-1.1.4/cppconn/config.h"<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;==修改为==&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 38&nbsp;&nbsp;&nbsp;&nbsp; "/home/chenjunjun/mysql-connector-c++-1.1.4/build/cppconn/config.h"<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost build]$ make install<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost build]$ cd<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$ <br /><br />### 设置<br /><br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$ echo "export LD_LIBRARY_PATH=~/usr/mysql_connect_c++/lib/" &gt;&gt; ~/.bashrc<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$ . ./.bashrc<br /><br />### 测试<br /><br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$ vi test.cc<br /><br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#include &lt;iostream&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#include &lt;string&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#include &lt;mysql_connection.h&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#include &lt;mysql_driver.h&gt;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;using namespace std;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;using namespace sql;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;int main(){<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Driver* driver;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Connection* conn;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;driver = get_driver_instance();<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;conn = driver-&gt;connect("数据库地址", "用户名", "用户密码");<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;conn-&gt;setAutoCommit(1);<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cout &lt;&lt; "DataBase connection autocommit mode = " &lt;&lt; conn-&gt;getAutoCommit() &lt;&lt; endl;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;delete conn;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;driver = NULL;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;conn = NULL;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return 0;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$ g++ test.cc -I ~/usr/mysql_connect_c++/include -L ~/usr/mysql_connect_c++/lib -l mysqlcppconn -o test<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$ ./test<br />&nbsp;&nbsp; &nbsp;DataBase connection autocommit mode = 1<br />&nbsp;&nbsp; &nbsp;[chenjunjun@localhost ~]$</div><img src ="http://www.cppblog.com/chenjunjun/aggbug/207986.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/chenjunjun/" target="_blank">chenjunjun</a> 2014-08-12 17:01 <a href="http://www.cppblog.com/chenjunjun/archive/2014/08/12/207986.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>