Frank Vilea
Frank Vilea

Reputation: 8487

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

I'm on Ubuntu 11.04. Everything works PHP, PHPMYADMIN, manual login to MySQL etc.

I have written a C application that uses MySQL. Now, when I start this application I receive the above error. I tried to prevent that from happening by linking the original file into the /tmp/ folder (ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock), however, after a while I start getting this error again - because my link has been removed, which is frustating.

What do I need to do to make this work?

Upvotes: 1

Views: 3251

Answers (2)

Mel
Mel

Reputation: 6167

The MySQL libraries are compiled with a default of /tmp/mysql.sock. The server is started up with /var/run/mysqld/mysql.sock and your $HOME/.my.cnf does not reflect this value in the [client] section.

If this is run without a valid $HOME you may need to use mysql_options with MYSQL_READ_DEFAULT_FILE.

Upvotes: 2

Tudor Constantin
Tudor Constantin

Reputation: 26871

Try linking the file in other location than /tmp/ and use it from there

Upvotes: 0

Related Questions