Skip to content

PythonMysql

Vitalii Koshura edited this page Apr 12, 2023 · 4 revisions

MySQLdb

Various BOINC tools depend on a Python extension module called "MySQLdb". You can get the source on mysql-python sourceforge project.

WARNING: currently (2003/08/28) BOINC requires version 0.9.2 of Python-MySQLdb, however this could be backported to 0.9.1 in the future as many Linux distributions seem to have 0.9.1.

Installation instructions

Lines beginning with "$" indicate example commands to type in bourne shell.

Lines beginning with "#" indicate example commands to type with write access to the install location (i.e. su or sudo)

Lines beginning with ">>> " indicate example commands to type in Python.

The 'shared module' options build a shared library for the Python-MySQLdb module that is loaded at Python run-time. This requires that you have a shared version of the MySQL client library installed, i.e. libmysqlclient.so.

Debian Linux: shared module

  1. Install
# apt-get install python-mysqldb

If you have multiple Python versions installed you may want to do

 # apt-get install python2.2-mysqldb
or
 # apt-get install python2.3-mysqldb

Red Hat Linux: shared module

  1. Download MySQL-python
$ wget http://easynews.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python2-0.9.2-1.i386.rpm
  1. Install
# rpm -i MySQL-python2-0.9.2-1.i386.rpm

Other Unix/Linux: shared module

  1. Download MySQL-python
$ wget http://easynews.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-0.9.2.tar.gz
  1. Unpack
$ gunzip -c MySQL-python-0.9.2.tar.gz | tar xf -
  1. Build
$ cd MySQL-python-0.9.2
$ python setup.py build
  1. Install
# python setup.py install

Unix/Linux: compiled statically into Python

  1. Download MySQL-python
$ wget http://easynews.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-0.9.2.tar.gz
  1. Unpack
$ gunzip -c MySQL-python-0.9.2.tar.gz | tar xf -
  1. Download Python
$ wget http://python.org/ftp/python/2.3/Python-2.3.tgz
  1. Unpack
$ gunzip -c Python-2.3.tgz | tar xf -
  1. Copy MySQL files
$ cp MySQL-python-0.9.2/{*.c,*.h} Python-2.3/Modules/
$ cp MySQL-python-0.9.2/_mysql_exceptions.py Python-2.3/Lib/
$ cp -r MySQL-python-0.9.2/MySQLdb Python-2.3/Lib/
  1. Enter the MySQL module in the Python extension setup file.
$ cd Python-2.3/
$ perl -wpi.bak -e "s,^_sre _sre.c,_mysql _mysql.c `mysql_config --cflags` `mysql_config --libs`\n$&," Modules/Setup
  (This adds the line '_mysql _msql.c [flags]' to Modules/Setup)

$ perl -wpi.bak -e 's,^LIBSUBDIRS=\s+,$&MySQLdb ,' Makefile.pre.in
  (This adds MySQLdb to the list of libraries to install)
  1. Configure python
$ cd Python-2.3/
$ ./configure --prefix=/usr/local
 or whatever path you want instead of /usr/local]
  1. Build
$ make

Troubleshooting: If you get undefined symbols or other compile errors in _mysql.c you probably didn't add the correct include directory for mysql. If you get unresolved symbols or other link errors involving _mysql.o or libmysql.a you probably didn't add the correct libraries. You may want to check Python and MySQLdb are working before installing by running ./python; see below for instructions.

  1. Install
$ cd ../Python-2.3/
# make install

Does it work?

You can check if your Python and/or MySQLdb was compiled and installed correctly like this:

$ python
>>> import MySQLdb
>>> MySQLdb.version_info
>>> MySQLdb.connect(db='databasename', user='username', passwd='userpassword')
Clone this wiki locally