linux下安装mysql和mysql++

来源:互联网 发布:linux操作系统中文版 编辑:程序博客网 时间:2024/06/07 08:04

Mysql++是官方发布的、一个为MySQL设计的C++语言的API,这个API的作用是使工作更加简单且容易。Mysql++为Mysql的C-Api的再次封装,它用STL(Standard Template Language)开发并编写,并为C++开发程序员提供象操作STL容器一样方便的操作数据库的一套机制。


安装mysql++前需要先安装mysql。

我的实验环境是centOS,使用yum安装mysql。

yum install mysql-devel

现在安装mysql++。

step1:下载安装包mysql++-3.2.0.tar.gz并解压。

step2:make三部曲。

./configure --prefix=/usr/local --enable-thread-checkmakemake install
step3:修改/etc/ld.so.conf文件,在文件内添加/usr/local/lib。如果是64位系统,需要添加/usr/local/lib64、/usr/lib64、/lib64等。(如果文件本来含有这些路径则无需添加。)然后执行命令:

# /sbin/ldconfig
step4:链接下文件。

# ln -s /usr/local/lib/libmysqlpp.so /usr/lib/libmysqlpp.so
step5:添加环境变量。(重启电脑后生效)

在./etc/profile文件中添加export LD_LIBRARY_PATH=$LD_LIBRARY_PATH/usr/local/lib。


测试例子:

//hello.cpp#include <iostream>#include <mysql++.h>#include <stdio.h>using namespace std;int main(){    cout<<"hello"<<endl;    getchar();   return 0;}
编译命令:

g++ -Wno-deprecated -L/usr/lib/mysql -lmysqlclient -L/usr/local/lib -lmysqlpp -Ilib -I/usr/include/mysql -I/usr/local/include/mysql++ -o test hello.cpp -lpthread
如果是64位系统,相应的命令为:

g++ -Wno-deprecated -L/usr/lib64/mysql -lmysqlclient -L/usr/local/lib64 -lmysqlpp -Ilib -I/usr/include/mysql -I/usr/local/include/mysql++ -o test hello.cpp -lpthread
如果能够编译成功,且不出现运行错误,则下一步可进行数据库的各种操作了。




原创粉丝点击