1. Windows上安裝MySQLdb
1.1 基于python2.7的安裝
下載MySQL_python?1.2.5?cp27?none?win_amd64.whl
python install MySQL_python?1.2.5?cp27?none?win_amd64.whl
或者
pip install MySQL-python
1.2 基于python3.5的安裝
MySQLdb的安裝很曲折贮乳,還是按照正常方法安裝嫩码,下載MySQL-python-1.2.5版本罪既,解壓后python setup.py install婿奔,發(fā)現(xiàn)怎么裝都會(huì)報(bào)錯(cuò)“ConfigParser.NoSectionError: No section:'metadata'”刹缝,
是不是python3.5不支持MySQLdb了? 谷歌一下烘挫,果不其然柬甥。python3不再支持mysqldb饮六。其替代模塊是PyMySQL(下載地址:https://github.com/PyMySQL/PyMySQL)苛蒲,趕緊下載安裝,修改好程序后窟扑,終于歡快的跑了起來。
python3 -m pip install PyMySQL
搞定嚎货。
2.linux上安裝MySQLdb
2.1 基于python2.7的安裝
首先知道一下內(nèi)容:
my.cnf 在/etc/下蔫浆,mysql_config在/usr/lib/mysql和/usr/bin下殖属。
my.cnf是配置文件克懊,存儲(chǔ)數(shù)據(jù)庫(kù)的位置七蜘,參數(shù)等信息。
mysql_config是命令橡卤,用于編譯mysql客戶端程序扮念。
1.下載MySQL-python-1.2.5版本
https://pypi.python.org/pypi/MySQL-python2.安裝依賴包
yum -y install python-devel mysql-devel3.解壓文件并修改site.cfg
unzip MySQL-python-1.2.5.zip
cd MySQL-python-1.2.5
找到本地MySQL安裝目錄下的mysql_config,將site.cfg文件中mysql_config修改為該地址(mysql_config = /usr/bin/mysql_config)碧库,并將threadsafe修改為False.
[root@iZuf6chjatdc17mvsvmdqtZ MySQL-python-1.2.5]# more site.cfg
[options]
# embedded: link against the embedded server library
# threadsafe: use the threadsafe client
# static: link against a static library (probably required for embedded)
embedded = False
threadsafe = False
static = False
# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /usr/bin/mysql_config
# http://stackoverflow.com/questions/1972259/mysql-python-install-problem-using-virtualenv-wind
ows-pip
# Windows connector libs for MySQL. You need a 32-bit connector for your 32-bit Python build.
connector = C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2
-
4.安裝
python setup.py build
python setup.py install
2.2 基于python3.5的安裝
python3 -m pip install PyMySQL