holy
holy

Reputation: 632

Connecting C to mysql

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

#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??
Thanks

Upvotes: 3

Views: 5533

Answers (4)

Aftnix
Aftnix

Reputation: 4589

In ubuntu/debian

$sudo apt-get install libmysqlclient libmysqlclient-dev

in centos/fedora/RHEL

$yum install mysql-devel

Upvotes: 4

Friedrich
Friedrich

Reputation: 5996

Insufficient. You need all the files for development. You need the header and proper libraries or you won't get anywhere. So if you are one some linux check out something like libmysql or search on the proposed download pages.

Upvotes: 1

user475353
user475353

Reputation:

Once you have installed the Client....you should be able to just link them? Or at least add the include/libs to your compiler?

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

Upvotes: 3

orlp
orlp

Reputation: 117641

You have to install the library:

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

Upvotes: 2

Related Questions