Compiling MySQLdb 1.2.3 on Windows 32 and 64 – Without need the MySQL Database 5.5 installed

Hi,

If you wish the module already compiled, access here: http://blog.victorjabur.com/2011/06/08/modules-python-library-compiled-for-windows-32-and-64-unofficial-windows-binaries-for-python/

First Thing: Follow this main steps to prepare the pre-requirements for compile this module:

http://blog.victorjabur.com/2011/06/05/compiling-python-2-7-modules-on-windows-32-and-64-using-msvc-2008-express/

1 – Compiling MySQLdb 1.2.3 for Mysql 5.5 database

1.1 – You will need to download the latest version of MySQL Connector C here: http://dev.mysql.com/downloads/connector/c/

* Important: Make the download properly for your platform (32 or 64 bits).

1.2 – Make the download of MySQLdb plugin here and extract to any folder: http://sourceforge.net/projects/mysql-python/

1.3 – Edit this file (MySQL-python-1.2.3/setup_windows.py) inside of folder extracted:

At Line 7 of the file, comment the two follow lines and add another, like this:

    #serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options['registry_key'])
    #mysql_root, dummy = _winreg.QueryValueEx(serverKey,'Location')
    mysql_root = ''

At Line 19, put the path to your Connector C installed:

    library_dirs = [ os.path.join(mysql_root, r'lib\opt'), 'C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt' ]
    libraries = [ 'kernel32', 'advapi32', 'wsock32', client ]
    include_dirs = [ os.path.join(mysql_root, r'include'), 'C:\Program Files\MySQL\MySQL Connector C 6.0.2\include' ]
    extra_compile_args = [ '/Zl' ]

Important: Specify the correct path for your platform (32 or 64 bits). Above the platform is 64 bits, to 32 bits use this path: “C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2”.

1.4 – Make the build:

python setup.py build --compiler msvc
python setup.py bdist_wininst

It’s finish.

The advantage os this technique an a comparison with others posts is:

1 – The MySQL Database is not required on machine (only the connector c)
2 – Not is necessary make the update on the windows registry:

# The Windows registry key for MySQL.
# This has to be set for Windows builds to work.
# Only change this if you have a different version.
registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0

Credits and References to this post:

http://chaos.weblogs.us/archives/327
http://www.fuyun.org/2009/12/install-mysql-for-python-on-windows/

Bye,
Victor Jabur

Advertisements

5 thoughts on “Compiling MySQLdb 1.2.3 on Windows 32 and 64 – Without need the MySQL Database 5.5 installed

  1. Aw, this was an incredibly nice post. Spending some time and actual
    effort to produce a superb article… but what
    can I say… I procrastinate a lot and don’t seem to get anything done.

  2. I think this is among the most significant info for me. And i am glad reading your article. But want to remark on some general things, The website style is wonderful, the articles is really great D. Good job, cheers bbkddekegedg

  3. i install mysql C connector “mysql-connector-c-6.1.6-winx64.msi” but i do not have a “C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt” directory, only “C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib”. i am getting the following message when i try to build: _mysql.c(34) : fatal error C1083: Cannot open include file: ‘config-win.h’: No such file or directory
    error: command ‘C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\BIN\\amd64\\cl.exe’ failed with exit status 2……..this is for windows 8.1 x64,python 2.7.9 x64 using visual express 2008. i modified “msvc9compiler.py”, and copied vcvars64 to “../amd64/vcvarsamd64.bat”. i am using the visual express 2008 CMD which i have used in the past to build python modules. any help is appreciated. thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s