C连接Mysql

#include <windows.h>
#include <mysql.h>
#include "stdio.h"

#pragma comment(lib,"libmySQL.lib")

int main()
{
    MYSQL mysql;
    mysql_init(&mysql);
    mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"yangyh");
    if(!mysql_real_connect(&mysql,"localhost","root","root","9099",MYSQL_PORT,NULL,0)){
        fprintf(stderr,"Failed to connect to database: Error: %s\n",mysql_error(&mysql));
        //printf("error\n");
    }else printf("success\n");

    return 1;
}

你可能感兴趣的:(mysql)