<< All Posts
Using MySQL C API for Linux

Hi, if you are using Ubuntu linux just type this message below:

sudo apt-get install mysql-server
sudo apt-get install libmysql-dev

And after, create an file with extention ā€œ.cā€ and put this code into the file:

#include <stdio.h>
#include <mysql/mysql.h>

void main(void) {
  MYSQL connection;

  if (mysql_real_connect(&connection, "hostname", "user", "password", "database", 1, NULL, 0)) {
    printf("Yes! Connected\n");
  } else {
    printf("Error %d : %s\n", mysql_errno(&connection), mysql_error(&connection));

When you compile it, you may put some variables. You have to use the command line below:

gcc -o test -L/usr/lib/mysql -lmysqlclient test.c

Have fun! :)

<< All Posts


šŸ‡§šŸ‡· šŸ‡ØšŸ‡¦