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

来源:互联网 发布:贵阳大数据学校招生 编辑:程序博客网 时间:2024/06/09 13:33

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)


/* 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包含进来


原创粉丝点击