ubuntu mysql c api的使用开发实例程序。
2011-11-16 14:37
781 查看
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
http://www.cyberciti.biz/tips/linux-unix-connect-mysql-c-api-program.html
http://www.cyberciti.biz/files/mysql-c-api.c.txt
http://dev.mysql.com/doc/refman/5.0/en/c.html
http://pkgs.org/download/libmysqlclient.so.16()(64bit)
/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包含进来
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
http://www.cyberciti.biz/tips/linux-unix-connect-mysql-c-api-program.html
http://www.cyberciti.biz/files/mysql-c-api.c.txt
http://dev.mysql.com/doc/refman/5.0/en/c.html
http://pkgs.org/download/libmysqlclient.so.16()(64bit)
/* See url for more info: http://www.cyberciti.biz/tips/linux-unix-connect-mysql-c-api-program.html */ #include <mysql.h> #include <stdio.h> #include <stdlib.h> 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包含进来
相关文章推荐
- ubuntu下使用eclipse c/c++开发arm linux程序
- ubuntu下使用phpstorm开发php程序
- 使用Python开发windows GUI程序入门实例
- 关于使用Spring和hibernate开发web程序的配置说明和简单实例的详细说明
- ubuntu16.04下使用wine 运行微信开发小程序
- Ubuntu下嵌入式开发环境搭建之使用MiniTools下载裸机程序
- 使用ADO封装类的数据库程序开发实例(上)
- 使用gSOAP开发实例(2) 股票信息服务端程序
- Ubuntu下用glade和GTK+开发C语言界面程序(三)——学习make的使用方法
- Ubuntu 14.04 + QT 计算器开发实例1-----全局变量的使用以及double、字符串类型互转
- 使用ADO封装类的数据库程序开发实例(下)
- Ubuntu 12.04使用Django + apache + mysql 开发web应用(一)
- 使用ADO封装类的数据库程序开发实例
- 使用ADO封装类的数据库程序开发实例[第二版] (上)
- 使用富盛Sbo-Addon程序开发框架轻松开发模态单据选择查询功能实例
- ubuntu下使用phpstorm开发php程序
- 使用gSOAP开发实例(2) 股票信息服务端程序
- Ubuntu10.04 下使用code Blocks 进行oci 程序开发
- Visual Studio 2017开发linux程序之libevent使用实例
- 在Ubuntu环境下用QT5开发树莓派的GPIO程序(使用wiringPi库)之二 引入wiringPi库