我是在Ubuntu系统下测试的

      此系统下,mysql安装: apt-get install mysql-server 等了有10多分钟

      然后又装了mysql-client: apt-get install mysql-client

      还不够还需要mysql的开发包: apt-get install libmysql++

     没有权限的话sudo 你懂的

      敲下代码

C代码   fatal error: mysql.h: No such file or directory_c代码
  1.   
  2.   
  3. int main(void){  
  4.   
  5.         if(!conn_ptr){  
  6. "mysql_init failed \n");  
  7. return  EXIT_FAILURE;  
  8.   
  9. "localhost","root","111111","mysql",0,NULL,0);  
  10.         if(conn_ptr){  
  11. "Connection success\n");  
  12. else{  
  13. "Connection failed\n");  
  14.   
  15.         return EXIT_SUCCESS;  
  16. }  

 编译

gcc -o testmysql testmysql.c

Java代码   fatal error: mysql.h: No such file or directory_c代码
  1. compilation terminated.  

 

然后修改gcc -o testmysql testmysql.c  -I/usr/include/mysql/

C代码   fatal error: mysql.h: No such file or directory_c代码
  1. testmysql.c:(.text+0x11): undefined reference to `mysql_init'  
  2. testmysql.c:(.text+0xc0): undefined reference to `mysql_close'  
  3. collect2: ld returned 1 exit statu  

 

最后修改

C代码   fatal error: mysql.h: No such file or directory_c代码
  1. gcc -o testmysql testmysql.c -I/usr/include/mysql/ -lmysqlclient -Wall -g  

成功

作者:柒月