Home  >  Q&A  >  body text

linux - When compiling, it prompts that the header file #include <mysql/mysql.h> does not exist, and Baidu did not solve it afterward.

#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);
某草草某草草2712 days ago1555

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:35:09

    $ sudo yum install mysql-devel -y    //RHEL,Centos,Fedora
    $ sudo apt-get install libmysqlclient-dev -y  //Ubuntu

    If it has been installed successfully, just find mysql.h的文件路径,-I and compile it

    $ sudo  find /usr/ -name 'mysql.h'
    $ gcc -I/usr/include/mysql ...
    

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-16 13:35:09

    You are using the mysql connector. You can download and install it from the mysql official website. Or if you use the system software source that comes with it (for example, CentOS7 comes with the mariadb-devel package), you can install it directly with the package manager

    reply
    0
  • Cancelreply