Help - Search - Members - Calendar
Full Version: Using Mysql With Python
OESF Portables Forum > Everything Else > Archived Forums > Distros, Development, and Model Specific Forums > Zaurus - Everything Development > Python
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 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/", line 64, in Connect
return Connection(*args, **kwargs)
File "/home/QtPalmtop/lib/python2.4/site-packages/MySQLdb/", 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

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.
Thanks for putting in the solution to your own problem ..
It could help someone tomorrow ... so thanks.
Lance Simms
QUOTE(nilch @ Oct 16 2007, 01:10 PM) *
Thanks for putting in the solution to your own problem ..
It could help someone tomorrow ... so thanks.

It did help me with MySQL 5.0 and MySQLdb 1.22 as well. Thank you.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.