Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL & C problem under Linux

Status
Not open for further replies.

Flappy

Programmer
Jul 30, 2002
35
AU
I've written a few programs in C that access the local MySQL database on my linux system, the problem is this when I run one of my C programs it comes up with this error:

Error on connect: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Then if I edit the socket entry in the /etc/my.cnf file to /tmp/mysql.sock and restart the mysql deamon my C programs work!

But then if I try to enter into MySQL by typing 'mysql -uroot -p' at the command line it comes up with this error:

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

If its not one error its another - how would I go about getting around this? is it another option that I add when compiling my programs?

This is an example of what options I use when compiling:

gcc testprog.c -o testprog -I/usr/local/mysql/include -L/usr/local/mysql/lib -lmysqlclient -lz


Thanks
 
The obvious answer is to use the mysql configured location
for your C program's socket. Probably too obvious.
Have you tried using /var/lib/mysql/mysql.sock modifying
your C programs /tmp location?
 
hmmm ok well /var/lib/mysql/mysql.sock must be the proper socket to use as that is the default setting that is in the my.cnf file, but how do I go about changing the /tmp location for my C program ?
 
does it work if you use the external ip of your machine rather than localhost?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top