Hi,

I am trying to execute a c program which extracts data from a mysql database.
I have installed mysql and created the desired database called "one"

The program uses the following if statment to try to connect to the database
and flag if connection is not successful:
-------------------------------------------------------------------------------
if (!mysql_real_connect(&mysql,"localhost","root","XXX","one",0,NULL,0))

{

        printf("\nError connecting to database\n\n");

        printf("Error: %s\n\n",mysql_error(&mysql));
        exit(1);

}
--------------------------------------------------------------------------------
where root is the username and XXX denotes the place wher I filled in my
password. The username and password used are the same as ones I use to successfully
connect to the database by starting up the client.


However, when I try to execute the code the program terminates at this point
and prints out the following:
--------------------------------------------------------------------------------
Error connecting to database

Error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.
                                            sock' (2)
--------------------------------------------------------------------------------

I understand that it is very difficult to spot the problem without viewing
the entire code but can anyone hazard a guess to why this is happening?
Does the c program need to be in any specific mysql directory?



note: if I try to connect to the server from the command line, while the
MySQL server is not started, using "./mysql -u root -pXXX" it will return
the error:
"Can't connect to local MySQL server through socket '/tmp/mysql.sock'"
Does the fact that the location of mysql.sock is different in each case?



Thanks in advance,
Cathal



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to