ubuntu mysql开发_ubuntu mysql c api的使用开发实例程序。

1.安装

apt-get install libmysqlclient-dev

2.mysql_config --libs

-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient

3.mysql_config --cflags

-I/usr/include/mysql  -DBIG_JOINS=1  -fno-strict-aliasing   -DUNIV_LINUX -DUNIV_LINUX

/*

See url for more info:

http://www.cyberciti.biz/tips/linux-unix-connect-mysql-c-api-program.html

*/

#include

#include

#include

int main(void) {

MYSQL *conn;

MYSQL_RES *res;

MYSQL_ROW row;

/* Change me */

char *server = "localhost";

char *user = "root";

char *password = "";

char *database = "mysql";

conn = mysql_init(NULL);

/* Connect to database */

if (!mysql_real_connect(conn, server,

user, password, database, 0, NULL, 0)) {

fprintf(stderr, "%s\n", mysql_error(conn));

exit(1);

}

/* send SQL query */

if (mysql_query(conn, "show tables")) {

fprintf(stderr, "%s\n", mysql_error(conn));

exit(1);

}

res = mysql_use_result(conn);

/* output table name */

printf("MySQL Tables in mysql database:\n");

while ((row = mysql_fetch_row(res)) != NULL)

printf("%s \n", row[0]);

/* close connection */

mysql_free_result(res);

mysql_close(conn);

return 0;

}

/LQmysql# gcc -o output-file $(mysql_config --cflags) mysql-c-api.c $(mysql_config --libs)

/LQmysql# ./output-file MySQL Tables in mysql database:

columns_priv

db

event

func

general_log

help_category

help_keyword

help_relation

help_topic

host

ndb_binlog_index

plugin

proc

procs_priv

servers

slow_log

tables_priv

time_zone

time_zone_leap_second

time_zone_name

time_zone_transition

time_zone_transition_type

user

警告: 隐式声明与内建函数 ‘exit’ 不兼容

把stdlib.h包含进来

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值