系統(tǒng)版本:os x 10.11.5
mysql版本:mysql-5.7.18-macos10.12-x86_64
python版本:Python 2.7.10
GCC版本:GCC 4.2.1
二、安裝python-mysqldb
1、從sourceforge 下載MySQL-Python,并解壓
2、修改site.cfg文件
如果直接安裝,會出現(xiàn)mysql_config not found錯誤,要解決這個錯誤,在MySQL-python的目錄中找到site.cfg文件,打開它,找到以下內容:
# The pathtomysql_config.
# Only use thisifmysql_configisnotonyourPATH,oryou have some weird
# setup that requires it. # mysql_config = /usr/local/bin/mysql_config
修改為:
# The pathtomysql_config.
# Only use thisifmysql_configisnotonyourPATH,oryou have some weird
setup that requires it. # mysql_config = /usr/local/mysql/bin/mysql_config
上文最后一句代碼指示的是mysql_config的地址,默認是屏蔽的狀態(tài);去掉這一句前面的#,并將mysql_config地址改為/usr/local/mysql/bin/mysql_config,因為這是mysql_config默認的真實地址(mac安裝mysql默認這個地址下有mysql_config文件)
3、安裝MySQL-Python
終端運行:
$ sudo python setup.py install
運行安裝程序并提示成功后,MySQL-Python就安裝成功了,這個時候可在終端窗口驗證:
$ Python
$ import MySQLdb
如果不報錯就說明安裝成功!至此安裝完成,開始寫連接數(shù)據(jù)庫的爬蟲