All pastes #908327 Raw Edit

Stuff

public text v1 · immutable
·published 2008-02-18 09:49 UTC
rendered paste body
CentOS 5.1 ships with MySQL-python-1.2.1-1 available. The Django documentation 
specifies a minimum version of 1.2.1-p2 and indeed, syncdb will fail with the 
stock CentOS package. As of this writing, 1.2.2 is the latest available and 
will be the version we install.

The easy route is to grab the source and compile it. Unfortunately, that 
leaves us hosed in the way of RPM dependencies. Instead, we will build our own 
RPM using the latest CentOS package and the latest source tarball.

Before doing anything else, install or update the following packages:

	$ yum -y install mysql
	                 mysql-devel
	                 mysql-server
	                 python
	                 python-devel
	                 rpm-build
	                 rpm-devel

Now, grab the latest SRPM of MySQL-python for CentOS from 
http://mirror.centos.org/centos/5.1/os/SRPMS/MySQL-python-1.2.1-1.src.rpm

Open a terminal and log in as superuser (su -).

Extract the SRPM contents with this command:

	$ rpm -Uvh MySQL-python-1.2.1-1.src.rpm

Then change into the extract location and list its contents:

	$ cd /usr/src/redhat
	$ ls
	BUILD  RPMS  SOURCES  SPECS  SRPMS

The tar.gz resides in the SOURCES directory. We want to place the newer one 
there too.

Download MySQL-python-1.2.2.tar.gz from the project's SourceForge home 
[http://sourceforge.net/projects/mysql-python/] and copy it to the SOURCES 
directory now.

For example, if you downloaded to /tmp you would use this command:

	$ cp /tmp/MySQL-python-1.2.2.tar.gz /usr/src/redhat/SOURCES/MySQL-python-1.2.2.tar.gz

Now, edit the spec file to use the new source tarball:

	$ vi SPECS/MySQL-python.spec

Change the Version string from 1.2.1 to 1.2.2 and save the file. You should 
end up with something like this:

	# Python major version.
	%{expand: %%define pyver %(python -c 'import sys;print(sys.version[0:3])')}
	
	Summary: An interface to MySQL
	Name: MySQL-python
	Version: 1.2.2
	Release: 1
	License: GPL
	Group: Development/Libraries
	
	[ more... ]

Further down in the spec file, there are three lines that you should comment 
out to avoid errors from rpmbuild. There is no need to package the object 
files referenced.

Change the following:

	/usr/%{_lib}/python%{pyver}/site-packages/MySQLdb/*.pyo
	/usr/%{_lib}/python%{pyver}/site-packages/MySQLdb/constants/*.pyo
	/usr/%{_lib}/python%{pyver}/site-packages/*.pyo

To:

	#/usr/%{_lib}/python%{pyver}/site-packages/MySQLdb/*.pyo
	#/usr/%{_lib}/python%{pyver}/site-packages/MySQLdb/constants/*.pyo
	#/usr/%{_lib}/python%{pyver}/site-packages/*.pyo

Now, build the RPM using the following command (you may need to be connected 
to the internet for the automated download of setuptools):

	$ rpmbuild -ba -v SPECS/MySQL-python.spec

The new RPM is now available in the RPMS directory. To install, run the 
command (substituting your architecture):

	$ rpm -i RPMS/x86_64/MySQL-python-1.2.2-1.x86_64.rpm

Django will now be able to use MySQL databases.