ZMySQLDA - from download to connection
Created by .
Last modified on 2003/08/05.
Why this how-to ?
I decided to write this how-to because I just
spent a whole day to get ZMySQLDA running,
mainly because of lack of good documentation.
I hope with it you can be ready in a matter of
minutes:)
Audience
The instructions here are for Unix users,
my own plataform was RH5.2 (Linux)
Before you Start:
- If you have installed Zope through the binary
version, reinstall it again from the source. The
binary version comes with its own pre-compiled
Python. I could not find a way to install MySQLdb
on it. Building from the source allows you to use
your own Python installation.
- You better install your Python from the source
too (do not forget to build --with-thread).
But if you do use the RPM get the 'devel'
RPM too, it will not work
with the plain RPM only.
Let's go:
- Download ZMySQLDA:
It is
here.
- Expand it at your top-level zope
directory. Its directory will actually
be at [zope-dir]/lib/python/Products after
expanded. Ignore the instructions to build
the mysql-module (src dir). We are going to use
MySQLdb instead.
- Download MySQLdb:
MySQLdb is a newer driver to MySQL than the one
that comes bundled with ZMySQLDA. You can get it
here.
- Expand MySQLdb at the "Products" directory
of you Zope installation.Then follow the
installation instructions for it. This driver has
lot of advantages over the old one: it is thread
safe, DB-API 2.0 compliant and well documented!
- Patch ZMySQLDA: Copy
ZMySQLDA.patch to the top-level zope dir and then
patch -p1 <ZMySQLDA.patch it!
- Restart Zope:You can
do it from Zope's Control Panel.
- Create your first ZMySQL
connection! Inside a Folder, add a
ZMySQL Database Connection Item. The tricky part,
the one that took me an hour to find out, is how
the "connection string" should be written. The
information wasn't anywhere I expected to find
(the ZMySQLdb or ZMySQLDA docs).
You have to write the connection string like this:
database[@host] user passwd
For example if you want to connect to the "Clients"
database at the same host where your Zope
installation is, with username 'me' and password
'secret' you can just write:
Clients me secret
That's it. Now you can add ZSQL Methods and
have fun!
Alan Pogrebinschi
|