原因:缺少libmysqlclient-dev,
安装:apt-get install libmysqlclient-dev
main.cpp
#include <iostream>
#include <mysql/mysql.h>
#include <stdlib.h>
using namespace std;
int main()
{
MYSQLmysql;
MYSQL_RES*result;
MYSQL_ROWrow;
mysql_init(&mysql);
mysql_real_connect(&mysql, "127.0.0.1", "root","123456",
"mydb", 0, NULL, 0);
mysql_query(&mysql, "select * from friends");
result =mysql_store_result(&mysql);
while ((row= mysql_fetch_row(result)))
{
cout<< row[0]<< " | "<< row[1]<< " | "<< row[2]<< " | "
<< row[3]<< " | "<< row[4]<< " | "<< row[5]<< " | "
<< endl;
}
mysql_free_result(result);
mysql_close(&mysql);
return0;
}
makefile
mydb:main.cpp
g++ -o mydbmain.cpp -lmysqlclient -I/usr/include/mysql/ -L/usr/lib/mysql
安装:apt-get install libmysqlclient-dev
main.cpp
#include <iostream>
#include <mysql/mysql.h>
#include <stdlib.h>
using namespace std;
int main()
{
}
makefile
mydb:main.cpp