CentOS和MacOS下安装MySQLdb

CentOS下安装MySQLdb

需要gcc,所以先安装gcc

yum install gcc python-devel

安装Python中的easy_install工具,它的作用类似于Ruby中gem

wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py -O - | python

下载MySQL-python

wget --no-check-certificate http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.3.tar.gz

tar -zxvf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3
vi site.cfg

把 mysql_config = /usr/local/mysql/bin/mysql_config 这一行前的#去掉,并且把mysql_config的路径设置正确。

python setup.py build
python setup.py install

如果gcc没有发现,则运行

yum install gcc python-devel

运行python

>>> import MySQLdb

无错误,则表示成功了

MacOS下安装MySQLdb

easy_install MySQL-python
easy_install MySQL-python --upgrade

运行python

>>> import MySQLdb

无错误,则表示成功了

你可能感兴趣的:(python,mysqldb)