1、拷贝Mysql服务器和客户端安装后的lib和include。
2、写sql测试代码
#include <stdio.h>
#include "/home/filecom/mas/lib/include/mysql.h"
#include <stdlib.h>
int main()
{
MYSQL *con;
con = mysql_init(NULL);
if(!mysql_real_connect(con,"172.19.112.192","masadmin","5t6y7u8i","mas",0,NULL,0))
{
fprintf(stderr, "%s\n", mysql_error(con));
exit(0);
}
char insert_str[512];
sprintf(insert_str,"INSERT INTO sms_outbox(sismsid,ExtCode,DESTADDR,MESSAGECONTENT,REQDELIVERYREPORT,MSGFMT,SENDMETHOD,REQUESTTIME,APPLICATIONID) VALUES('zzw123','888','18714510983','张兆伟',1,15,1,NOW(),'007')");
mysql_set_character_set(con, "utf8");
if (mysql_query(con, insert_str))
{
fprintf(stderr, "%s\n", mysql_error(con));
exit(0);
}
mysql_close(con);
printf("successful!\n");
}
3、最重要的是编译
gcc -I/home/filecom/mas/lib/include csql.c -L/home/filecom/mas/lib/lib
-lmysqlclient -o csql