<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="en-us"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="Generator" content="Microsoft Word 97"> <title>How To use BIBUS With MySQL</title> <meta content="Claude PAOLI" name="author"> <meta content="Version 06/29/2005" name="description"> </head> <body link="#0000ff" vlink="#800080"> <h1 style="color: rgb(51, 51, 255);"><big><font><big><big><font><big><big><big><big><font><big><big><font size="2"><big><big><big>How To use BIBUS With MySQL <small><small><span style="color: rgb(0, 0, 0);">– 06/29/2005 – Claude PAOLI</span></small></small></big></big></big></font></big></big></font></big></big></big></big></font></big></big></font></big></h1> <big><font size="2"><big>To access MySQL databases, BIBUS needs MySQL for Python (previously MySQLdb). The project and downloads can be found at </big></font></big><big><font size="2"><big>sourceforge :</big></font></big><big><font size="2"><big> </big></font><a href="http://sourceforge.net/projects/mysql-python"><font size="2"><big>http://sourceforge.net/projects/mysql-python</big></font></a><font size="2"><big>.</big></font></big> <h2><big><font size="2"><big><u>Depending on MySQL server versions you want to connect</u> you can typicaly use :</big></font></big></h2> <ul> <li><big><font size="2"><big>mysql-Python version 1.0.0 for MySQL Server version 4.0.x and earlier</big></font></big></li> <li><big><font size="2"><big>mysql-Python version 1.2.0 for MySQL Server version 4.1.x and earlier (this means that 4.0.x servers can be accessed with mysql-Python version 1.2.0). Unfortunately, version 1.2.0 seems to be bogus when connect/disconnect/connect sequence is performed with BIBUS without restarting it ! So, as there is no other stable version available at the moment, we recommend the use of the unstable 1.2.1c3 version (the described bug and some other that were corrected by a BIBUS new coding are no longer encountered).</big></font></big></li> </ul> <div style="margin-left: 40px;"><big><font size="2"><big><span style="text-decoration: underline;">Note :</span> take care of the Python and MySQL versions used to buid the installation package you could download. If you don't find the correct combination (MySQL version used to build can be the same or higher than the MySQL server you want to access, but Python version must be exaclty the same), you have to build your own package.</big></font></big><br> </div> <h2><big><font size="2"><big><u> <p>Compiling MySQL for Python version 1.2.1c3 :</p> </u></big></font></big></h2> <p><big><font size="2"><big>This version is set as unstable so there is no compiled version available, and even for stable versions not all OS/Python combinations are.</big></font></big></p> <p><big><font size="2"><big>Note : This procedure describes my experience with the 1.2.1c3 version, but I assume that it will be approximately the same for other versions. </big></font></big></p> <h3><big><font size="2"><big><b><u>For all platforms</u></b> : </big></font></big></h3> <p><big><font size="2"><big>You obviously have to install Python on your system (I used Python 2.4 for my tests on Windows 2000 and Python 2.3 with Mandrake Linux 10.1). Then, you have to download the MySQL-python source from </big></font><a href="http://sourceforge.net/projects/mysql-python"><font size="2"><big>SOURCEFORGE</big></font></a><font size="2"><big>, and expand this file to a directory that will be named <b><i>MySQL-Python-1.2.1c3</i></b> in this document. You also need to have the correct MySQL development package installed. For this version of python-MySQL, the 4.1.x is needed At this point, the procedure will begins to be platform dependant.</big></font></big></p> <h3><big><font size="2"><big><b><u>For Linux Users</u></b> : </big></font></big></h3> <p><big><font size="2"><big>Download and install the MySQL Libraries and header file from </big></font><a href="http://dev.mysql.com/downloads/"><font size="2"><big>MySQL Download</big></font></a><font size="2"><big> (I used the Linux x86 RPM package : <span style="font-style: italic;">MySQL-devel-4.1.12.1-i386.rpm</span>). Note that this will not interferes with previous versions of MySQL server installed, only other versions of the development packages have to be removed (I compiled with a MySQL server 4.0 installed and running). Be sure to have installed the C compiler packages (I used the GCC packages provided in standard with my Linux installation). Then open a shell command line and move to the <b><i>MySQL-Python-1.2.1c3 directory</i></b>, then you only have to follow the README file. At the prompt type :</big></font></big></p> <p style="margin-left: 80px; font-style: italic;"><big><font size="2"><big>$ python setup.py clean<br> $ python setup.py build<br> $ python setup.py bdist_rpm</big></font></big></p> <p><big><font size="2"><big>At this point you have a RPM package built in the dist subdirectory of the <b><i>MySQL-Python-1.2.1c3 </i></b>directory. You now have to install it and it’s done.</big></font></big></p> <p><big><font size="2"><big><span style="text-decoration: underline;">Note :</span> If you only want to install MySQL-Python, you can, with an administrator account, replace the last command line by </big></font></big><big><font size="2"><big><span style="font-style: italic;">$ python setup.py install.</span> It will aso work fine, if you previoulsy removed some MySQL-Python</big></font></big><big><font size="2"><big> potentially</big></font></big><big><font size="2"><big> installed package.</big></font></big></p> <h3><big><font size="2"><big><b><u>For Windows 32 users</u></b> :</big></font></big></h3> <p><big><font size="2"><big>It can be much more longer if you don’t have some required tools, but it will finally work (I did it !). </big></font></big></p> <p><big><font size="2"><big>My procedure have been inspired by the Martin Bless description (</big></font><a href="http://mail.python.org/pipermail/python-list/2004-December/255184.html"><font size="2"><big>http://mail.python.org/pipermail/python-list/2004-December/255184.html</big></font></a><font size="2"><big>) and the </big></font><a href="http://www.vrplumber.com/programming/mstoolkit/"><font size="2"><big>Building Python Extensions with the MS Toolkil Compiler</big></font></a><font size="2"><big> page.</big></font></big></p> <p><big><font size="2"><big> First download the MySQL server Windows installation file from </big></font><a href="http://dev.mysql.com/downloads/"><font size="2"><big>MySQL Download</big></font></a><font size="2"><big> (not the Windows Essential !) – Note that you could also download the Without installer and unzip the file to a chosen directory, but the files were approximately the same size, and the install/uninstall programs are fine (I used the V4.1.12-Win32). Before launching the install file, please be sure to have the latest Microsoft Installer on your system (3.0 don’t works with the file I have downloaded). Then launch installation procedure, select a custom installation, and if you only want to compile mysql-Python without running MySQL server, select only the installation of Developer Components (the default is set to install all except this component, you will have to reverse all the default selections). These files will be installed on the <span style="font-weight: bold; font-style: italic;">C:\Program Files\MySQL\MySQL Server 4.1</span> directory (if <span style="font-style: italic;">C:\Program Files</span> is your program files default directory). This directory will be assumed as the MySQL server installation directory later in this document. </big></font></big></p> <p><big><font size="2"><big>We now have to install a C compiler and all needed extensions. We will use the free MS Toolkit C++ compiler, so we have to download it first from </big></font><a href="http://msdn.microsoft.com/visualc/vctoolkit2003"><font size="2"><big>http://msdn.microsoft.com/visualc/vctoolkit2003</big></font></a><font size="2"><big> and then install it. We also have to install the.NET FrameWork Version 1.1 (it is already installed on Windows XP, but Windows 2000 user will find an install program at </big></font><a href="http://www.microsoft.com/downloads/details.aspx?familyid=262D25E3-F589-4842-8157-034D1E7CF3A3&displaylang=en"><font size="2"><big>http://www.microsoft.com/downloads/details.aspx?familyid=262D25E3-F589-4842-8157-034D1E7CF3A3&displaylang=en</big></font></a><font size="2"><big> – Note that optional Language pack could be needed depending on you language). Then we can install the .Net FrameWork SDK (download at </big></font><a href="http://www.microsoft.com/downloads/ThankYou.aspx?familyId=9b3a2ca6-3647-4070-9f41-a333c6b9181d&displayLang=en"><font size="2"><big>http://www.microsoft.com/downloads/ThankYou.aspx?familyId=9b3a2ca6-3647-4070-9f41-a333c6b9181d&displayLang=en</big></font></a><font size="2"><big> – Note that you will maybe have to select a different download language file download). Some extensions were also needed from the platform SDK, so you have to install it (I used the Windows Server 2003 SP1 Platform SDK downloaded at </big></font><a href="http://www.microsoft.com/downloads/details.aspx?familyid=EBA0128F-A770-45F1-86F3-7AB010B398A3&displaylang=en"><font size="2"><big>http://www.microsoft.com/downloads/details.aspx?familyid=EBA0128F-A770-45F1-86F3-7AB010B398A3&displaylang=en</big></font></a><font size="2"><big>). </big></font></big></p> <p><big><font size="2"><big>The Python 2.4 disutils (used by mysql-Python <span style="font-style: italic;">setup.py</span> to build the package) have not been designed to deal with MS Toolkit Compile, so some changes have to be made to the<span style="font-style: italic;"> msvccompiler.py</span> original file. First download the </big></font><a href="http://www.vrplumber.com/programming/mstoolkit/msvccompiler.patch"><font size="2"><big>msvccompiler.patch</big></font></a><font size="2"><big> file provided by the </big></font><a href="http://www.vrplumber.com/programming/mstoolkit/"><font size="2"><big>Building Python Extensions with the MS Toolkil Compiler</big></font></a><font size="2"><big> page. Then we have to use the patch unix utility that can be found at <a href="http://unxutils.sourceforge.net">http://unxutils.sourceforge.net</a>. Launch a command line and move to the Python 2.4 disutils directory (<span style="font-weight: bold; font-style: italic;"><Python 2.4 install Path> \Lib\distutils</span>) copy the <span style="font-style: italic;">patch.exe</span> program and <span style="font-style: italic;">msvccompiler.patch</span> file to this directory then run <span style="font-weight: bold; font-style: italic;">> patch.exe msvccompiler.py msvccompiler.patch</span>. We have now to change the detection value for the installed SDK. First check the registry to find the <span style="font-weight: bold; font-style: italic;">HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MicrosoftSDK\InstalledSDKs</span> Key. Copy the SSID key that looks like <span style="font-style: italic;">8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3</span>. Then edit the msvccompiler.py file and search for <i>freeSDK = r"SOFTWARE\Microsoft\MicrosoftSDK\InstalledSDKs\</i>. Then replace the SSID at the end of this line by the one you found in your registry. </big></font></big></p> <p><big><font size="2"><big>We now have to set some environment variables to be sure that the needed programs and libraries will be found. Note that when you install the SDKs and the MS ToolKit, the installers will propose some of these setting to be made directly to the system. If you choose to, you will not have to set some of the values described below. I have chosen to create a batch file named <span style="font-weight: bold; font-style: italic;">SetEnv.bat </span>(to be able to compile later versions without so much work) that looks like :</big></font></big></p> <dir><big> </big> <dir><big></big><big></big> <p style="font-weight: bold; font-style: italic;"><big><font size="2"><big>REM You have to change some of the path according to your Python 2.4 and MS SDKs Installation paths<br> Set PATH=C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin;C:\Program Files\Microsoft SDK\Bin;C:\Program Files\Python2.4.1;%PATH%<br> Set INCLUDE=C:\Program Files\Microsoft Visual C++ Toolkit 2003\include;C:\Program Files\Microsoft SDK\include;C:\Program Files\Python2.4.1\include;%INCLUDE%<br> Set LIB=C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib;C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib;C:\Program Files\Microsoft SDK\Lib;C:\Program Files\Python2.4.1\libs;%LIB%</big></font></big></p> <big style="font-weight: bold; font-style: italic;"> </big> <p style="font-weight: bold; font-style: italic;"><big><font size="2"><big>REM You have to change the path according to your MySQL Server installation path<br> set mysqlroot=C:\Program Files\MySQL\MySQL Server 4.1</big></font></big></p> <big style="font-weight: bold; font-style: italic;"> </big> <p style="font-weight: bold; font-style: italic;"><big><font size="2"><big>REM The default mysqlclient used by mysql-Python is set to mysqlclient_r library that doesn’t exist with windows, so use the mysqlclient library<br> set mysqlclient=mysqlclient</big></font></big></p> <big style="font-weight: bold; font-style: italic;"> </big> <p style="font-weight: bold; font-style: italic;"><big><font size="2"><big>REM Set the lib path to MySQL libraries (the setup.py file tries to but the path seems to be have been changed)<br> REM You have to change the path according to your MySQL Server installation<br> Set LIB=C:\Program Files\MySQL\MySQL Server 4.1\lib\opt;%LIB%</big></font></big></p> </dir> </dir> <p><big><font size="2"><big>Save the created file in the <b><i>MySQL-Python-1.2.1c3 </i></b>directory, we will use it later. </big></font></big></p> <p><big><font size="2"><big>The setup.py file located in the <b><i>MySQL-Python-1.2.1c3 </i></b>directory also needs some changes. Edit this file and find the <i>if sys.platform == "win32":</i> line. After this line, add in the if statement <i>add extra_compile_args = ""</i> (with the correct indentation according to python syntax).</big></font></big></p> <p><big><font size="2"><big>HERE WE ARE ! If everything is OK, we can now try to compile and build the install file ! First open a command line and move to the <b><i>MySQL-Python-1.2.1c3 </i></b>directory. Then type the commands :</big></font></big></p> <dir> <dir><big></big><big></big> <p style="font-style: italic;"><big><font size="2"><big>> SetEnv.bat<br> > python setup.py clean<br> > python setup.py build<br> > python setup.py bdist_wininst</big></font></big></p> </dir> </dir> <p><big><font size="2"><big>If everything goes right, the compilation process provides some warning messages, but you should obtain a <b><i>MySQL-python.exe-1.2.1c3.win32-py2.4.exe</i></b> file in the <b><i>dist</i></b> subdirectory of the <b><i>MySQL-Python-1.2.1c3 </i></b>directory. Just execute this file to install python-MySQL !</big></font></big></p> <p><big><font size="2"><big><span style="text-decoration: underline;">Note :</span> If you only want to install MySQL-Python, you can, with an administrator account, replace the last command line by</big></font></big><big><font size="2"><big><span style="font-style: italic;"> > python setup.py install.</span> It will aso work fine, if you previoulsy removed some MySQL-Python</big></font></big><big><font size="2"><big> potentially</big></font></big><big><font size="2"><big> installed package.</big></font></big></p> <h3><big><font size="2"><big><b><u>For MAC Users</u></b> : </big></font></big></h3> <p><big><font size="2"><big>I don’t have such platform so I can’t help. I assume that it will look like the Linux one.</big></font></big></p> </body> </html>