1.windows 比较简单,下载exe文件直接安装。
2.liunx环境两种安装
简单:yum install MySQL-python
复杂:需要自己源码编译,依赖包比较多
a. gcc
b. setuptools
c. python-dev
步骤:
B.
$ tar xfz MySQL-python-1.2.3.tar.gz
$ cd MySQL-python-1.2.3
$ cd MySQL-python-1.2.3
$whereis
mysql_config
mysql_config: /usr/bin/mysql_config
$ vim site.cfg
修改mysql_config为mysql配置文件的路径 /usr/bin/mysql_config
$ vim site.cfg
修改mysql_config为mysql配置文件的路径 /usr/bin/mysql_config
还要修改
threadsafe = False
$ python setup.py build
$ sudo python setup.py install
$ python setup.py build
$ sudo python setup.py install
在python环境下
>>> import MySQLdb
/usr/local/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/lib/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.pyc, but /app/MySQL-python-1.2.5 is being added to sys.path
/usr/local/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/lib/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.pyc, but /app/MySQL-python-1.2.5 is being added to sys.path
安装成功
-------------------------------------------------------------------------------------------------------------------------------
安装过程中报,error: command 'gcc' failed with exit status 1
用yum install gcc 显示已经是安装最新版本
未安装mysql-devel包
解决方法:yum install mysql-devel
参考地址:http://blog.csdn.net/wklken/article/details/7271019
http://blog.csdn.net/agoago_2009/article/details/9492765