Gregory Piñero gregpinero at
Tue Jun 14 20:20:29 CEST 2005

While waiting for answers to the above questions, I went ahead and
tried the following:

1. Downloaded the RPM for the server's version of MySql:

2. Copy file to server, and extract to a new folder i made called rpmmysql:
[gpinero at intel1 gpinero]$ cd rpmmysql/
[gpinero at intel1 rpmmysql]$ rpm2cpio
/home/gpinero/MySQL-devel-3.23.56-1.i386.rpm | cpio -d -i
3936 blocks
[gpinero at intel1 rpmmysql]$ ls
[gpinero at intel1 rpmmysql]$ cd usr
[gpinero at intel1 usr]$ ls
bin  include  lib
[gpinero at intel1 usr]$ cd include/
[gpinero at intel1 include]$ ls
[gpinero at intel1 include]$ cd mysql
[gpinero at intel1 mysql]$ ls
chardefs.h  m_ctype.h    my_net.h         mysql.h          sslopt-case.h
dbug.h      m_string.h   my_no_pthread.h  mysql_version.h  sslopt-longopts.h
errmsg.h    my_config.h  my_pthread.h     my_sys.h         sslopt-usage.h
history.h   my_global.h  mysql_com.h      raid.h           sslopt-vars.h
keymaps.h   my_list.h    mysqld_error.h   readline.h       tilde.h
[gpinero at intel1 mysql]$

3. Edited to include the new directory.  Here's my whole file
just in case you need it:

#!/usr/bin/env python

Python interface to MySQL

MySQLdb is an interface to the popular MySQL_ database server for
Python.  The design goals are:

- Compliance with Python database API version 2.0 [PEP-0249]_

- Thread-safety

- Thread-friendliness (threads will not block each other) 

MySQL-3.22 through 4.1 and Python-2.3 through 2.4 are currently

MySQLdb is `Free Software`_.

.. _MySQL:
.. _`Free Software`:
.. [PEP-0249]


import os
import sys
from distutils.core import setup
from distutils.extension import Extension

mysqlclient = os.getenv('mysqlclient', 'mysqlclient_r')
mysqlstatic = eval(os.getenv('mysqlstatic', 'False'))
embedded_server = (mysqlclient == 'mysqld')

name = "MySQL-%s" % os.path.basename(sys.executable)
if embedded_server:
    name = name + "-embedded"
version = "1.2.1c3"

extra_objects = []

if sys.platform == "win32":
    mysqlroot = os.getenv('mysqlroot', None)
    if mysqlroot is None:
        print "You need to set the environment variable mysqlroot!"
        print "This should be the path to your MySQL installation."
        print "Probably C:\Program Files\MySQL 4.1\ or something like that."

    include_dirs = [os.path.join(mysqlroot, "include")]
    library_dirs = [os.path.join(mysqlroot, "libs")]
    libraries = ['zlib', 'msvcrt', 'libcmt', 'wsock32', 'advapi32']
    if mysqlstatic:
            library_dirs[0], mysqlclient+'.lib'))

    def config(what):
        from os import popen
        f = popen("mysql_config --%s" % what)
        data =
        if f.close(): data = []
        return data

    # This dequote() business is required for some older versions
    # of mysql_config
    def dequote(s):
        if (s[0] == "'" or s[0] == '"') and (s[0] == s[-1]):
            s = s[1:-1]
        return s
    include_dirs = [ dequote(i[2:]) for i in config('include') if
i.startswith('-i') ]

    if mysqlclient == "mysqlclient":
        libs = config("libs")
    elif mysqlclient == "mysqlclient_r":
        libs = config("libs_r")
    elif mysqlclient == "mysqld":
        libs = config("embedded")
    library_dirs = [ dequote(i[2:]) for i in libs if i.startswith("-L") ]
    libraries = [ dequote(i[2:]) for i in libs if i.startswith("-l") ]

    # Workaround for a pre-4.1.9 bug
    if "z" not in libraries:

    extra_compile_args = config("cflags")

    if mysqlstatic:
            library_dirs[0],'lib%s.a' % mysqlclient))

classifiers = """
Development Status :: 5 - Production/Stable
Environment :: Other Environment
License :: OSI Approved :: GNU General Public License (GPL)
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows :: Windows NT/2000
Operating System :: OS Independent
Operating System :: POSIX
Operating System :: POSIX :: Linux
Operating System :: Unix
Programming Language :: C
Programming Language :: Python
Topic :: Database
Topic :: Database :: Database Engines/Servers

metadata = {
    'name': name,
    'version': version,
    'description': "Python interface to MySQL",
    'long_description': __doc__,
    'author': "Andy Dustman",
    'author_email': "andy at",
    'license': "GPL",
    'platforms': "ALL",
    'url': "",
    'download_url': "" \
                    "MySQL-python-%s.tar.gz" % version,
    'classifiers': [ c for c in classifiers.split('\n') if c ],
    'py_modules': [
    'ext_modules': [

4. Tried building again:
[gpinero at intel1 MySQL-python-1.2.1c3]$ python2.4 build
running build
running build_py
running build_ext
building '_mysql' extension
gcc -pthread -shared build/temp.linux-i686-2.4/_mysql.o -lz
-lmysqlclient_r -o build/lib.linux-i686-2.4/
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

More information about the Python-list mailing list