1. Installing the sudo yum install Mysql-devel installation components and libraries
2.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <mysql/mysql.h>int main ( int argc, const char *argv[]) { mysql mysql; Mysql_res *result; Mysql_row ROW; Mysql_init (&mysql); Mysql_real_connect (&mysql, "127.0.0.1", "SYSWJ", "123456", "Sysdb", 0, NULL, 0 ); mysql_query (&mysql, "select * from Stu"); result = Mysql_store_result (&mysql); while (row = mysql_fetch_row (result)) { printf ("%s%s%s %s %s\n", row[0], row[1], ROW[2], row[3], row[4], row[5]); } Mysql_free_result (result); Mysql_close (&mysql); return 0;}
3. Compilation: GCC test-l/usr/lib/mysql-lmysqlclient
4. Run:
[Email protected] document]$/a.out 950 li Yong m CS951 Zhang San F EN952 John Doe F - DC953 will be large f DC954 can be large m CS955 Hello F 27
References: http://www.linuxidc.com/Linux/2011-12/49133.htm
??
MySQL the following C connect MySQL database