Chinaunix首页 | 论坛 | 博客
  • 博客访问: 240576
  • 博文数量: 35
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 273
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-27 23:34
个人简介

To follow the path,look to the master,follow the master.

文章分类

全部博文(35)

文章存档

2019年(1)

2018年(1)

2017年(1)

2016年(8)

2015年(24)

分类: C/C++

2016-05-01 02:35:51

CentOS
1.yum list mysql-devel
   yum install mysql-devel-???
需安装mysql依赖包???版本号

/*****************************以下代码是从网上拷贝,学习使用****************************************************/
/*练习mysql数据库的连接*/
#include
#include


int main()
{
    MYSQL mysql;
    int t, r;
    /*连接之前,先用mysql_init初始化MYSQL连接句柄*/
    mysql_init(&mysql);
    /*使用mysql_real_connect连接服务器,其参数依次为MYSQL句柄,服务器IP地址, 
 *     登录mysql的用户名,密码,要连接的数据库等*/
    if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "test", 0, NULL, 0)) {
        printf("Error connecting to Mysql!\n");
    }else {
        printf("Connected Mysql successful!\n");
    }
    /*关闭连接*/
    mysql_close(&mysql);
    return 0;
}

其中whereis  mysql 可查询链接路径,供编译使用。
编译命令: 
        gcc -o mysql mysql.c -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient






阅读(5730) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~