OESF | ELSI | pdaXrom | OpenZaurus | Zaurus Themes | Community Links | Ibiblio


Welcome Guest ( Log In | Register )

> Using Mysql With Python, It doesn't work for me...
post Oct 15 2007, 04:02 PM
Post #1

Group: Members
Posts: 36
Joined: 29-March 05
Member No.: 6,732

I thought I'd try out the Python/PyQt/MySQL combination, but I've hit a snag that I can't handle. Any words of wisdom would be very welcome.

The machine is a C3000 with stock ROM.

I installed the Zaurus Python Image v2.4 from pyqplayer.sourceforge.net: files

Python runs fine, as far as I can tell.

For MySQL, I installed
That works fine using the mysql app: as zaurus or root I can create and populate databases. No passwords set yet.

But from python, I can't connect to MySQL. I've created a test database called 'junk' and here's what happens when I try to access it.

$ python
Python 2.4 (#1, Jan 5 2005, 19:21:20)
[GCC 2.95.1 19990816 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import qt
>>> import MySQLdb
>>> ms = MySQLdb.connect(host='localhost',user='zaurus',db='junk',passwd='')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/home/QtPalmtop/lib/python2.4/site-packages/MySQLdb/__init__.py", line 64, in Connect
return Connection(*args, **kwargs)
File "/home/QtPalmtop/lib/python2.4/site-packages/MySQLdb/connections.py", line 109, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")

The MySQL daemon is running (or the mysql app wouldn't have worked). The directory
is empty.
There are no error reports in dmesg.
Running as root gives the same error.

I'm totally new to Python, and I've no idea what to try next.

Cheers and TIA

Go to the top of the page
+Quote Post
Start new topic
post Oct 16 2007, 12:13 PM
Post #2

Group: Members
Posts: 36
Joined: 29-March 05
Member No.: 6,732

Apologies for bumping my own post, but after more searching I found the answer and I thought I'd post it in case anyone else should get bitten.

The Python code was looking for the connection socket as /var/run/mysqld/mysql.sock, but the directory was empty.

In /etc/mysql/my.cnf, the socket location was given as /tmp/mysql.sock and indeed that socket file exists. So the solution was to add:
as an extra parameter to the MySQLdb.connect() call. Magic.

Hope that helps someone.
Go to the top of the page
+Quote Post

Posts in this topic

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


RSS Lo-Fi Version Time is now: 21st October 2016 - 09:23 PM