Warning

This document hasn't been checked for compatibility with current versions of Plone. Use at your own risk.

How to connect with a MySQL database when Plone & Zope are running on a windows machine.

by Kenneth Van baelen last modified Dec 06, 2009 09:28 PM
How can you connect to a MySQL database when Plone & Zope are running on windows? This tutorial will explain everything step by step and gives the solution to one of the most common problem : how can you register Python in the windows registry.

Introduction

I was struggling for a long time to make a connection from within plone with an external database when Plone was running on a windows machine. When you install zope, python and plone on windows using the windows installer the python version isn’t registered in the windows registry. Therefore you will not be able to install the MySQL-python-1.2.2.win32-py2.4.exe package and without the package it will be impossible to make a connection with your database.

 

Add python to the windows registry

The first thing we have to do is add python to the registry. There are two ways to do this:

  • You can add python to the windows registry by running the regsetup.py script located in the folder Plone/Python/Lib/site-packages/win32/scripts folder. You can run the script by dragging and dropping it on the python.exe icon.
  • You can do it all by yourself:

First we need to access the windows registry:

        • In windows click on start – run
        • type in regedit and click on the ok button, a new window will open

Then we need to create some new keys

        • Go to HKEY_LOCAL_MACHINE
        • Go to SOFTWARE
        • Right click on the SOFTWARE folder and select new – key
        • Enter Python
        • Right click on the Python folder and select new – key
        • Enter Pythoncore
        • Right click on the pythoncore folder and select new – key
        • Enter your version number of python, only the first 2 numbers
          for example 2.4
        • Right click on the 2.4 folder and select new – key
        • Enter Installpath
        • Right click on the 2.4 folder and select new – key
        • Enter PythonPath
        • Right click on the 2.4 folder and select new – key
        • Enter Version

When all the keys are created we must give some off the keys a value. Do the following:

o       Click on the folder Installpath, in the right window you see an object called (default) of the type REG_SZ right click on it and choose the option modify and enter the path to your python.exe
For example C:\Plone\Python

o       Click on the folder PythonPath, in the right window right click on the object of the type REG_SZ called (default) and select modify. Enter the path to the python\lib folder and to the python\DLLs. Separate both paths with an ;
For example C:\Plone\Python\lib;C:\Plone\Python\DLLs

o       Click on the folderVersion, in the right window right click on the object of the type REG_SZ called (default) and select modify. Type in the full version number of your python. For example 2.4.3

 

Install the database adapter

Before we can send any queries to a database we need to connect to it. Therefore we need a Database adapter. These are specific to certain RDBMS.

The database adapter that you need to connect with an MySQL database can be found at Http://www.zope.org/Members/adustman/Products/ZMySQLDA. Download and decompress it. In the decompressed folder you’ll find the ZMySQLDA in the subdirectory lib/python/products. Copy the ZMySQLDA folder to the folder C:\Plone\Zope\lib\python\products.

 

Install the MySQL-python package

In the readme file of the database adapter we see that it uses another package. Download and install the correct MySQL-python package for your python version.

I used the MySQL-python-1.2.2.win32-py2.4.exe package because I’m running python 2.4.3. You’ll see now that python is registered in the windows registry the installation isn’t giving any errors.

 

Restart Zope

When both the MySQL and the database adapter are installed restart your zope server. After you restarted it go to the root folder of your plone website and add a Z MySQL database Connection. The connection string is of the type database user password

 

This tutorial was written by Kenneth Van Baelen on Tuesday April 24, 2007. Feel free to add some extra info,  comments, remarks or improvements


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.