title: Using C sockets to connect to MYSQL database
body: <p>Am writing an application for a Point of Sale TERMINAL , the manual for the terminal restricts direct MYSQL connection from the terminal, All connections should be done using Sockets. How can I connect to a MYSQL database using C sockets? Below is my working C program that establishes a TCP connection to specified ip and port.</p>
  
  <pre><code>    /*
       * Create a TCP socket
       * @Author Salim Said
       * Jan 2 2015 17:00hrs
      */
  
      #include&lt;stdio.h&gt;
      #include&lt;winsock2.h&gt;
      #pragma comment(lib,"ws2_32.lib") //Winsock Library
  
      int main(int argc , char *argv[])
      {
          WSADATA wsa;
          SOCKET s;
          struct sockaddr_in server;
  
          printf("\nInitialising Winsock...");
          if (WSAStartup(MAKEWORD(2,2),&amp;wsa) != 0)
          {
              printf("Failed. Error Code : %d",WSAGetLastError());
              return 1;
          }
  
          printf("Initialised.\n");
  
          //Create a socket
          if((s = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET)
          {
              printf("Could not create socket : %d" , WSAGetLastError());
          }
  
          printf("Socket created.\n");
  
  
          server.sin_addr.s_addr = inet_addr("74.125.235.20");
          server.sin_family = AF_INET;
          server.sin_port = htons( 80 );
  
          //Connect to remote server
          if (connect(s , (struct sockaddr *)&amp;server , sizeof(server)) &lt; 0)
          {
              puts("connect error");
              return 1;
          }
  
          puts("Connected successfully");
  
          return 0;
      }
  </code></pre>