Yes, MySQL treats "localhost" as "use the UNIX domain socket". So you still have problems connecting to the UNIX socket, but TCP sockets work fine.
If you do (on linux as root) netstat -lp, this will show all listening sockets, and what programs have them open. It may be your mysqld still isn't listening on the socket that you think it is.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
returns a "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)"
Obviously, the '/var/lib/mysql/mysql.sock' file is the default socket_file. But even when I pass my own socket file to the connect routine, I just get the same error with my socket file name substituted.
When I used to use python to access a database at a previous working environment, I would choose a port number, make an empty file in my user space, and connect using the port number and the empty file as a socket_file. But I cannot seem to make that work in my present environment.
What do you think?
p.s: The world-rw was a suggestion from an anwer to a similar question regarding pyflag that I found from googling my error.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am getting the following error:
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")
A colleague installed mysql for me under /opt/mysql, but I cannot get a connection through socket '/opt/mysql/mysql.sock', either.
It doesn't matter whether I am connecting as -u root, or as myself, -u kreaseck. It doesn't matter whether I am running python as root, or as myself.
I have tried using a socket file in my home directory ... no luck.
I have made the mysql/data directory world-read-writeable ... no luck.
Any ideas out there?
Thanks.
-- Barbara
Eureka!
I was using 'localhost' literally.
When I substituted my machine name (even though mysql is running on this machine) it works just fine.
Thanks.
Yes, MySQL treats "localhost" as "use the UNIX domain socket". So you still have problems connecting to the UNIX socket, but TCP sockets work fine.
If you do (on linux as root) netstat -lp, this will show all listening sockets, and what programs have them open. It may be your mysqld still isn't listening on the socket that you think it is.
Are you certain mysqld is running?
Check your global configuration file (/etc/my.cnf, or possibly somewhere in /opt), since that determines the correct socket location.
Making your files world-rw is a really bad idea.
I can see mysqld running via 'ps -ef | grep mysqld'.
/etc/my.cnf indicates a socekt file at /tmp/mysql.sock
When mysqld is running, I can see that file exists.
I can use mysql at the command line, but I cannot connect through python.
% python
>>> import MySQLdb
>>> db=MySQLdb.connect('localhost','user','password','database')
returns a "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)"
Obviously, the '/var/lib/mysql/mysql.sock' file is the default socket_file. But even when I pass my own socket file to the connect routine, I just get the same error with my socket file name substituted.
When I used to use python to access a database at a previous working environment, I would choose a port number, make an empty file in my user space, and connect using the port number and the empty file as a socket_file. But I cannot seem to make that work in my present environment.
What do you think?
p.s: The world-rw was a suggestion from an anwer to a similar question regarding pyflag that I found from googling my error.