Connecting C to mysql

I am connecting C to mysql and then creating a database.
My code:

#include <mysql.h>
#include <my_global.h> 

int main(int argc, char **argv)
{MYSQL *conn;
conn = mysql_init(NULL);
if (conn == NULL) {
  printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
  exit(1);}
if (mysql_real_connect(conn, "localhost", "zetcode", "passwd", NULL, 0, NULL, 0) == NULL)
 {printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
  exit(1);}
if (mysql_query(conn, "create database testdb")) {
 printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
  exit(1);
  }
mysql_close(conn);}

      

But I don't have the headers mysql.h and my_global.h
How can I get them?
thank

+3


source to share


4 answers


Once you've installed the Client ... can you just link them? Or at least add include / libs to your compiler?



http://www.mysql.com/downloads/

+3


source


On ubuntu / debian

$sudo apt-get install libmysqlclient libmysqlclient-dev

      



in centos / fedora / RHEL

$yum install mysql-devel

      

+4


source


You need to install the library:

http://dev.mysql.com/downloads/connector/c/

+2


source


Inadequate. You need all the development files. You need headers and libraries, or you're not going anywhere. So, if you are one of Linux, check something like libmysql or search on the suggested download pages.

+1


source







All Articles