linux mysql 找不到 <mysql/mysql.h>
linux mysql 找不到 <mysql/mysql.h>
原因:缺少libmysqlclient-dev,
安装:apt-get install libmysqlclient-dev
main.cpp
#include <iostream>
#include <mysql/mysql.h>
#include <stdlib.h>
using namespace std;
int main()
{
MYSQL
mysql;
MYSQL_RES *result;
MYSQL_ROW row;
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);
return 0;
}
makefile
mydb:main.cpp
g++ -o mydb main.cpp -lmysqlclient -I/usr/include/mysql/ -L/usr/lib/mysql
MYSQL_RES *result;
MYSQL_ROW row;
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);
return 0;
}
makefile
mydb:main.cpp
g++ -o mydb main.cpp -lmysqlclient -I/usr/include/mysql/ -L/usr/lib/mysql