Menu

Compiling MySQLdb when MySQL 4.1 is installed

2004-09-01
2012-09-19
  • Arnar Birgisson

    Arnar Birgisson - 2004-09-01

    I thought this might help someone.

    I only have MySQL 4.1 installed and needed to connect to it from Python. Compiling and installing MySQLdb didn't work, the code segfaulted on the first "select".

    To get around this, I took these steps after the normal "python setup.py build/install" stuff:

    I downloaded the _static_ binary version of MySQL 4.0 (at the time 4.0.20) from mysql.com, it's the first one in the list. I then untarred it under /opt on my machine. This creates /opt/mysql-standard-4.0.20.

    Then I went to the source directory of MySQLdb and compiled the _mysql module with these two command lines:

    gcc -pthread -fno-strict-aliasing \    -DNDEBUG -O3 -march=i486 -mcpu=i686 -fPIC \    -I/opt/mysql-standard-4.0.20-pc-linux-i686/include \    -I/usr/include/python2.3 \    -c _mysql.c \    -o build/temp.linux-i686-2.3/_mysql.o

    gcc -pthread -shared \    build/temp.linux-i686-2.3/_mysql.o \    /opt/mysql-standard-4.0.20-pc-linux-i686/lib/libmysqlclient_r.a \    -lz -lcrypt \    -o build/lib.linux-i686-2.3/_mysql.so

    This creates a _mysql.so that is statically linked to the client library of MySQL 4.0. Then I ran "python setup.py install" to install this new file.

    You can connect to a 4.1 server with an earlier version library, but the user you log on as has to have  a old style password hash in the mysql.users. Old style hashes are 16 bytes long and new ones are 45 bytes long and always start with an asterisk (*). See http://dev.mysql.com/doc/mysql/en/Old_client.html if you can't connect.

    Arnar

     
    • Arnar Birgisson

      Arnar Birgisson - 2004-09-01

      Sorry, one correction, the last path in the 4th paragraph should be /opt/mysql-standard-4.0.20-pc-linux-i686.

      I should also mention that statically linking _mysql.so increases it's size from 53k to 235k in my case. One could install the 4.0 client library as a shared library along the 4.1 but this will probably cause tremendous problems if you are running f.x. python interpreters inside mod_python and your mod_php is linked against mysql 4.1.

      Arnar

       
    • Andy Dustman

      Andy Dustman - 2004-09-07

      Try 1.1.2. You never did say what version of MySQLdb you were trying this with, though.

       
    • Arnar Birgisson

      Arnar Birgisson - 2004-09-08

      Sorry, this was 1.0.0.

      I tried 1.1.2, and it had _mysql_Exception misspelled as _mysql_Execption in thre lines (in _mysql.c). I corrected that but then I get:

        File "/usr/lib/python2.3/site-packages/MySQLdb/__init__.py", line 64, in Connect
          return Connection(*args, **kwargs)

        File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 102, in __init__
          self.autocommit(0)

        File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 118, in autocommit
          s.autocommit(self, flag)

      TypeError: function takes exactly 1 argument (2 given)

      I will look more into this.

      Thanks for the tip.

      Arnar

       
    • Arnar Birgisson

      Arnar Birgisson - 2004-09-08

      Removed the "self" from line 118 in connections.py and now everything works dandy :o)

      Arnar

       
    • Andy Dustman

      Andy Dustman - 2004-09-11

      I think all these problems are now fixed in 1.1.4. I actually tested with MySQL-4.1.4a this time.

       
    • Anonymous

      Anonymous - 2004-09-17

      Just to let you know, I was unable to compile with RPM install of MYSQL 4.1.4-0 using MySQLdb 1.1.4 until I added a missing comma on the end of line 28 in setup.py.  After this path was included, the 'build' worked and I installed.

       
      • Andy Dustman

        Andy Dustman - 2004-09-24

        Fixed in 1.1.5

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.