搞清楚操作系统什么版本,根据操作系统的版本32位/64位,到官网下载相应的包。32位若不行,可安装64位。
MySQL-server-community-5.1.62-1.rhel5
MySQL-devel-community-5.1.62-1.rhel5
MySQL-shared-compat-5.1.62-1.rhel5
MySQL-client-community-5.1.62-1.rhel5
安装顺序 server client devel shared
若出现找不到库 或者库不匹配时 时devel和shared的版本有问题,可尝试装64位
相关命令:
rpm -qa | grep MySQL 查看已安装的mysql
rpm -e MySQL-client-community-5.1.62-1.rhel5 卸载相应的包
rpm -ql MySQL-client-community-5.1.62-1.rhel5 查看安装到哪里去了
编译连接数据库代码
g++ -c hello.cpp -I /usr/include/mysql (mysql,h的路径)
链接连数据库.o
g++ hello.o MySQLwrapper.o -o test -L /usr/lib/mysql -lmysqlclient
也可以一步编译+链接
g++ *.cpp -o test -I /usr/include/mysql/ -L /usr/lib/mysql -lmysqlclient (动态链接库libmysqlclient的路径)