DWQA QuestionsCategory: Development ToolWhen compiling, the header file "include < MySQL / MySQL. H > does not exist, and Baidu has not solved it
Gu Chang Lin asked 1 month ago
#include <mysql/mysql.h>
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW *row;

char *server = "localhost";
char *user = "root";
char *password = "1";

conn = mysql_init(NULL);
if(!mysql_real_connect (conn,server,user,password,database,0,NULL,0))
{
    fprintf(stderr,"%s\n",mysql_error(conn));
    exit(1);
}
if(mysql_real_query(conn,"select * from student"))
{
    fprintf(stderr,"%s\n",mysql_error(conn));
    exit(1);
}
res = mysql_use_result(conn);
while((row = mysql_fetch_row(res)) != NULL)
{
    printf("%s\t%s\t%s\n",row[0],row[1],row[2]);
}
mysql_free_result(res);
mysql_close(conn);
2 Answers
Best Answer
Yang Bo Dong answered 1 month ago
$ sudo yum install mysql-devel -y    //RHEL,Centos,Fedora
$ sudo apt-get install libmysqlclient-dev -y  //Ubuntu

If the installation is successful, findmysql.hFile path for,-ICompile can

$ sudo  find /usr/ -name 'mysql.h'
$ gcc -I/usr/include/mysql ...
zuch answered 1 month ago

You are using MySQL connector. You can download and install it on MySQL official website. Or if you use the system software source (for example, CentOS 7 comes with MariaDB devel package), you can install it directly with the package manager