<< 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;
  mysql_init(&connection);

  if (mysql_real_connect(&connection, "hostname", "user", "password", "database", 1, NULL, 0)) {
    printf("Yes! Connected\n");
    mysql_close(&connection);
  } else {
    printf("Fail!\n");
    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

rodolfo.io

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