linux环境下使用C语言连接MySQL数据库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <stdio.h> #include "mysql.h" //使用MYSQL类库函数 int main(void) { MYSQL *connp = mysql_init(NULL); if(!connp) { printf("error 1\n"); return -1; } connp = mysql_real_connect(connp, "localhost", "root","", "test", 0, NULL, 0); //数据库连接信息 ip 用户名 密码 数据库名 if(connp) { printf("connect ok ...\n"); } else { printf("connect error ...\n"); } mysql_close(conn_ptr); return 0; } |
直接使用 gc…