Failed to connect to MYQL Server

Discussion in 'Server Operation' started by dinesh.4126, Sep 29, 2009.

  1. dinesh.4126

    dinesh.4126 New Member

    Hi,
    I am using UBUNTU Distro For Mysql Client and Trying to connect to Mysql Server on Debain Distro.And on client side written a C API for row access of table location.
    Code:
    
       1. #include <stdio.h>  
       2. #include <stdlib.h>  
       3. #include "mysql.h"  
       4.    
       5. int main()  
       6. {  
       7.    MYSQL *conn;  
       8.    MYSQL_RES *res;  
       9.    MYSQL_ROW row;  
      10.    
      11.    char *server = "amitsaini";  
      12.    char *user = "root";  
      13.    char *password = "rrr777"; /*set me first */  
      14.    char *database = "location";  
      15.    
      16.    conn = mysql_init(NULL);  
      17.    /* Connect to database */  
      18.    if (!mysql_real_connect(conn, server,  
      19.          user, password, database, 0, NULL, 0)) {  
      20.       fprintf(stderr, "%s\n", mysql_error(conn));  
      21.       exit(1);  
      22.    }  
      23.    
      24.    /* send SQL query */  
      25.    if (mysql_query(conn, "show tables")) {  
      26.       fprintf(stderr, "%s\n", mysql_error(conn));  
      27.       exit(1);  
      28.    }  
      29.    
      30.    res = mysql_use_result(conn);  
      31.    
      32.    /* output table name */  
      33.    printf("MySQL Tables in mysql database:\n");  
      34.    while ((row = mysql_fetch_row(res)) != NULL)  
      35.       printf("%s \n", row[0]);  
      36.    
      37.    /* close connection */  
      38.    mysql_free_result(res);  
      39.    mysql_close(conn);  
      40. }
    
    yatin@yatin-desktop:~/Desktop$ gcc -L/usr/local/lib/mysql -I/usr/local/include/mysql -o select select.c\
    -lmysqlclient
    yatin@yatin-desktop:~/Desktop$ ./select
    Unknown MySQL server host 'amitsaini'
     
    Last edited: Sep 29, 2009
  2. falko

    falko Super Moderator Howtoforge Staff

    Is amitsaini listed in /etc/hosts?
     

Share This Page