linux 下链接mysql练习

来源:互联网 发布:淘宝密码修改 编辑:程序博客网 时间:2024/06/08 02:25

编译命令如下
hzz@hzz-pc:~/code/testCode$ g++ -I /usr/include/mysql/ /home/hzz/code/testCode/connect2.c -L /usr/lib/mysql -lmysqlclient -o connection2
hzz@hzz-pc:~/code/testCode$ ./connection2

#include <stdlib.h>#include <stdio.h>#include "mysql.h"int main(int argc,char *arg[]){  MYSQL myconnection;  mysql_init(&myconnection);  if(mysql_real_connect(&myconnection,"localhost","test","test","testDb1",0,NULL,0))    {      printf("connection success");      mysql_close(&myconnection);    }  else    {      fprintf(stderr,"connection failed\n");      if(mysql_errno(&myconnection))      {          fprintf(stderr,"Connection error %d %s",mysql_errno(&myconnection),mysql_error(&myconnection));      }     } return 0;}
0 0