linux下安装mysql++
官方网站下载mysql++
tar 命令解压
./configure --prefix=/local //安装路径自定义
问题:
checking for MySQL library directory... configure: error: Didn't find mysqlclient library in '/usr/lib64 /usr/lib /usr/lib64/mysql /usr/lib/mysql /usr/local/lib64 /usr/local/lib /usr/local/lib/mysql /usr/local/mysql/lib /usr/local/mysql/lib/mysql /usr/mysql/lib/mysql /opt/mysql/lib /opt/mysql/lib/mysql /sw/lib /sw/lib/mysql'
解决方法:sudo apt-get install libmysqlclient
然后locate libmysqlclient去查找你的系统中的libmysqlclient.so library在哪个文件下(我的/usr/lib/x86_64-linux-gnu)
注意:(使用locate之前先sudo updatedb手动更新数据库下,因为locate是经过数据库来查找的,而数据库默认自动更新是一天一次。这样可能导致你locate不到今天刚刚生成的文件)
重新使用命令:./configure --prefix=/local --with-mysql-lib=/usr/lib/x86_64-linux-gnu
问题消除 ,
make
sudo make install
测试连接mysql demo
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
// Get database access parameters from command line
const char* db = 0, *server = 0, *user = 0, *password = "";
db = "healthcareweb";
server = "11.0.17.208";
user = "root";
password = "123456";
// Connect to the sample database.
mysqlpp::Connection conn(false);
if (conn.connect(db, server, user, password)) {
cout << "success. " << endl;
} else {
cout << "false. " << endl;
}
return 0;
}
遇到问题:
error while loading shared libraries: libmysqlpp.so.3: cannot open shared object file: No such file or directory
原因:
1) 如果共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令
采用第二种解决方法。解决了问题,完成安装