centos下安装MySQL-python

1) 下载MySQL-python

wget https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c

2) 解压缩

unzip MySQL-python-1.2.5.zip

cd MySQL-python-1.2.5

3)修改mysql配置路径, 否则提示找不到配置文件

修改 setup_posix.py 文件

vim setup_posix.py


修改 27行 mysql_config.path = "mysql_config"

mysql_config.path = “/usr/local/mysql/bin/mysql_config“


4)安装python MySQLdb

python setup.py build

sudo python setup.py install

5)测试

$ python

Python 2.7.11 (default, Aug  6 2016, 01:58:12) 

[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import MySQLdb

/usr/local/python2.7/lib/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/python2.7/lib/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.pyc, but /home/spider/develop/MySQL-python-1.2.5 is being added to sys.path

Traceback (most recent call last):

  File "", line 1, in

  File "MySQLdb/__init__.py", line 19, in

    import _mysql

  File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in

  File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__

ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory


提示找不到   libmysqlclient.so.18 

解决办法:

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


6) 重新测试,成功:

$ python
Python 2.7.11 (default, Aug  6 2016, 01:58:12) 

[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import MySQLdb

>>> 


最后,作个小gg,本人个人数据API网站,提供各种数据API服务,欢迎访问 云数达 http://www.yunshuda.cn

你可能感兴趣的:(centos下安装MySQL-python)