September 28th, 2003, 09:12 PM
How to tell MySQLdb where mysql.sock is?
Outisde of python I can connect to mysql from php, perl and I have phpMyAdmin running.
my socket is located in /var/lib/mysql/mysql.sock
when I first installed mysql the interactive mysql client would look for the socket at /tmp/mysql.sock
I can't remember how i fixed it, but i think it was an environment variable
enough background - my current problem is that python is also looking in /tmp/mysql.sock when I run
>>> import MySQLdb;
>>> db_conn = MySQLdb.connect('localhost','matt');
i also pass the password to connect.. but none of that matters becuse I get this error:
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")
How can i inform python and MySQLdb of the mysql installation directories??
I discovered unix_socket and called connect(...,'unix_socket='/var/lib/mysql/mysql.sock');
is there a better way than this??
I'm worried that I'll get other connection problems until the mysql path's are set.
thanks in advance.
September 29th, 2003, 08:26 AM
Hi Balzi, too be perfectly honest i have no idea, i've never had a problem connecting to MySQL/PostgreSQL/SQLite..
Anyway I got this example from the Python Cookbook, it uses the port option aswell as host and i figured it might give you some ideas?
# Create a connection object, then use it to create a cursor
Con = MySQLdb.connect(host="127.0.0.1", port=3306,
user="joe", passwd="egf42", db="tst")
Cursor = Con.cursor()
# Execute an SQL string
sql = "SELECT * FROM Users"
# Fetch all results from the cursor into a sequence and close the connection
Results = Cursor.fetchall()
September 30th, 2003, 08:45 PM
I've got the basics down by combing devshed and from the Python tutorials at python.org and here.
it seems weird that python can't find the socket handle without an explicit pointer but php and perl can..
anyway, I only have to specify it on opening the connection.. if I get no other issues I'll probably just write it off as a no-solution oddity.
thanks again for hte speedy reply.
nice to have helpful moderators.
September 30th, 2003, 09:08 PM
Very welcome Balzi, glad i could help! I have to agree with you, it's very strange that python couldn't find the connection.. especially when perl and PHP can, Mmmm. Ah well if it works then fine, prob some totaly obscure system problem
October 1st, 2003, 09:08 AM
maybe mentioning this problem to the python newsgroup would be fruitful... if indeed they can't come up with a solution, at least this problem will be noted for future versions of python or something.
however, i have NO idea how to get in contact with those guys, but i'm sure thorough rummaging through python.org will give some leads...
October 1st, 2003, 10:50 AM
Good idea CV
Now i cant tell you fro sure if http://www.dbforums.com/f97/ and googles comp.lang.python group are one and the same but i have my suspisions about it .. In any case give it a go if your interested.
October 2nd, 2003, 03:17 AM
my only reservation with posting to comp.lang.python is that no-one seems to share my problem..
I can't tell if it occurs for other people, but then i am using Python 2.3.. so maybe it's a bug, maybe it's not.
but, I am still hestitant to jump into the arena with the "big guys" and tell them that something they did is stuffed. Frogive my Frenench.
course, they might not see it that way.. and I could just wear the abuse for newbieness and stupid-question-asker and general wrong place to ask flames.
October 2nd, 2003, 09:09 AM
Hey i know what you mean, i had this error where i tried to send an email and it crashed the windows kernal (hense the leaning *nix). I also had python outputing a line "worker thread.." when using the socket module or one of the modules whoch use it i.e. urllib.
Anyway I reported them on the Python bug bored and low and behold, it was just me lol.
I dont think it's an error with Python 2.3 or the MySQLdb module, so many use them every day, the error would be all over the place, not to mention fixed , it's just one of those lil things.. you should feel special
June 24th, 2004, 06:39 PM
I know this is an old post but I ran into the same problem and did a google search on the error string. My hope is that people running into the same problem will find this in similar manner and now will also have a fix. This page was last in a list of only four results.
For complete documention read the file connections.py that comes with MySQLdb you can find it in the tarball of the package http://sourceforge.net/project/showf...ease_id=102893 or in your python dir: mine is /usr/lib/python2.2/site-packages/MySQLdb/ but yours will vary.
Here is how you specify the socket to use.
con = MySQLdb.Connection(host='your_host', user='your_user', passwd='your_passwd', unix_socket='path_to_mysql.sock')
You'll have to figure out the rest yourself. On my platform MySQLdb was trying to connect to /var/lib/mysql/mysql.sock but my socket is in /tmp/mysql.sock. If you can't find your socket and you're on a linux box try find / -name mysql.sock
Best of luck
November 18th, 2004, 08:26 PM
Why is it that whenever I have really obscure problems with things, the only right answer I find is in really old devshed threads?
Yeah, thread necromancy sucks, but I've spent HOURS on this already, and I googled it, and the right answer was here all along.
November 23rd, 2004, 03:23 PM
when you search google use
your question site:forums.devshed.com