1, the environment is centos6.5 32-bit system, Python version is 2.7.12,mysql version is 5.5.22. Prepare the required compression pack, mysql-python-1.2.4b4.tar.gz pip-6.0.7.tar.gz setuptools-12.0.3
2, using Python to operate MySQL first need to import MYSQLDB module, before installing this module finally installed Setuptools and Pip, before this need to install a good zlib zlib-devel module.
#yum install-y zlib-devel bzip2-devel xz-libs xz wget git tar gcc gcc-c++ OpenSSL openssl-devel pcre-devel python-devel l Ibevent automake autoconf libtool make git
Go to Python extract directory, recompile install python2.7 (otherwise error, zlib module can not find)
#./configure--prefix=/usr/local/python27 && make && make install
Setuptools unzip into the post-compression directory, compile and install
Python setup.py Build
Python setup.py Install
I'm done with a soft link to the Easy_install command.
Pip installation Ibid.
3, Decompression Mysql-python bag
Go to Mysql-python Extract directory, vim site.cfg file
Remove mysql_config =/usr/local/mysql/bin/mysql_config before the line, and set the path of the mysql_config correctly (you can use the which mysql_config command to find its path)
Change the Treadsafe=true option to false.
Save exit.
If importing the MySQLdb module fails, error: Importerror:libmysqlclient.so.18:cannot open Shared object file:no such file or directory
According to the last hint, should be unable to find a libmysqlclient.so.18 file, so go to the MySQL installation directory to find this file and make a soft connection to the/usr/lib
Ln-s/usr/local/mysql/lib/libmysqlclient.so.18/usr/lib/libmysqlclient.so.18
(If it is a 64-bit system, the previous step should be ln-s/usr/local/mysql/lib/libmysqlclient.so.18/usr/lib64/libmysqlclient.so.18)
Import again without an error.
Centos6.5 python2.7 Connect MySQL Database