MySQL-python 安装

1、下载mysql-python:

官网地址:https://sourceforge.net/projects/mysql-python/files/mysql-python/

MySQL-python 安装_第1张图片

2、解压

sudo tar -zxvf MySQL-python-1.2.3.tar

cd MySQL-python-1.2.3

3、在安装前需进行配置

     a、修改setup_posix.py中的mysql_config.path为你mysql安装目录的mysql_config路径

     b、修改site.cfg中的threadsafe = False,去掉mysql_config前的注释,并改为mysql_config = /usr/local/mysql/bin/mysql_config

     c、执行命令:

         export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql

         sudo ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so /usr/lib/libmysqlclient.so.14

         sudo ldconfig (这个很重要,否则后面会报错ImportError: libmysqlclient.so.14: cannot open shared object file)

4、编译安装

  1)python setup.py build

    若安装过程中碰到问题:unable to execute gcc: No such file or directory
               error: command 'gcc' failed with exit status 1

             1、执行命令:yum install -y gcc    

             2、执行命令:yum install python-devel 

 

  2)sudo python setup.py install

5、测试

python

>>> import MySQLdb

你可能感兴趣的:(python)