sudo apt-get install mysql-server mysql-client
Re-install the development package
Code:
sudo apt-get install Libmysqlclient15-dev
After installation, add header file in C code
Code:
#include <mysql.h>
Compile method:
Code:
GCC $ (mysql_config--cflags) xxx.c-o xxx $ (mysql_config--libs)
You can test it with the following code
Code:
#include <mysql.h>
#include <stdio.h>
Main () {
MYSQL *conn;
Mysql_res *res;
Mysql_row ROW;
char *server = "localhost";
Char *user = "root";
Char *password = "";
Char *database = "MySQL";
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, "Show Tables")) {
fprintf (stderr, "%s\n", MYSQL_ERROR (conn));
Exit (1);
}
res = MYSQL_USE_RESULT (conn);
printf ("MySQL Tables in MySQL database:\n");
while (row = mysql_fetch_row (res)) = NULL)
printf ("%s \ n", row[0]);
Mysql_free_result (RES);
Mysql_close (conn);
}
Http://blog.sina.com.cn/s/blog_494e45fe0100k9p8.html
C Connect Database MySQL