Copy Code code as follows:
Add E:\WAMP\BIN\MYSQL\MYSQL5.5.8\LIB path to the VC tool
Add Libmysql.lib to the project Settings-link library module
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <winsock.h>
#include "E:\wamp\bin\mysql\mysql5.5.8\include\mysql.h"
void Main () {
MYSQL *conn;
Mysql_res *res;
Mysql_row ROW;
char *server = "localhost";
Char *user = "root";
Char *password= "";
Char *database= "Test";
Char sql[1024]= "SELECT * from Chinaren";
Conn=mysql_init (NULL);
if (!mysql_real_connect (conn,server,user,password,database,0,null,0)) {
fprintf (stderr, "%s\n", MYSQL_ERROR (conn));
Exit (1);
}
if (mysql_query (Conn,sql)) {
fprintf (stderr, "%s\n", MYSQL_ERROR (conn));
Exit (1);
}
Res=mysql_use_result (conn);
while ((row = mysql_fetch_row (res))!=null) {
printf ("%s\n", row[2]);
}
Mysql_free_result (RES);
Mysql_close (conn);
}