#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <mysql/mysql.h>
#include <arpa/inet.h>
#include <pthread.h>
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
// 数据库连接参数
char *server = "172.17.0.1";
char *user = "root";
char *password = "123456";
char *db="key_manage_center";
int port=3306;
int main(){
// 初始化 MySQL 连接
conn = mysql_init(NULL);
if (conn == NULL) {
fprintf(stderr, "mysql_init() failed\n");
return 0;
}
// 连接到数据库
if (mysql_real_connect(conn, server, user, password, db, port, NULL, 0) == NULL) {
fprintf(stderr, "Connection failed: %s\n", mysql_error(conn));
return 0;
}
}
标签:NULL,mysql,char,MySQL,include,连接,conn From: https://www.cnblogs.com/tytbook/p/18378475