title: C program mysql connection
body: <p>I'm working on a simple c program that has to connect to my database, then do a query and then close the connection.</p>
  
  <pre><code>int main()
  {
      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", "root", "root", NULL, 8889, NULL, 0)) {
          printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
          exit(1);
      }
  
      if (mysql_query(conn, "create database testdb")) {
          printf("Error %u: %s",mysql_errno(conn), mysql_error(conn));
          exit(1);
      }
  
      mysql_close(conn);
      return 0;
  }
  </code></pre>
  
  <p>This code compiles but when I run it, it will exit after the <code>mysql_query()</code> statement. </p>
  
  <p>The following error is returned:</p>
  
  <pre><code>Error 2006: MySQL server has gone away
  </code></pre>
  
  <p>I used google to search for an answer and ended up here:</p>
  
  <p><a href="http://dev.mysql.com/doc/refman/5.0/en/gone-away.html" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.0/en/gone-away.html</a></p>