在Python 中安裝 MySQLdb 報錯如下:
Could not find a version that satisfies the requirement MySQLdb (from versions: )No matching distribution found for MySQLdb
查詢后了解到,MySQLdb 包只支持到python3.4,因此,如果你是python3.5+的用戶,可以安裝另外一個mysql驅動:PyMySQL
PyMySQL 是在 Python3.x 版本中用於連接 MySQL 服務器的一個庫,Python2中則使用mysqldb。
PyMySQL 遵循 Python 數據庫 API v2.0 規范,並包含了 pure-Python MySQL 客戶端庫。
安裝與MySQLdb方法一樣:
安裝 MySQLdb
pip install MySQLdb
安裝PyMySQL
pip3 install PyMySQL
如果還是習慣使用MySQLdb,可以在需要的項目中,在__init__.py中添加如下兩行:
import pymysql pymysql.install_as_MySQLdb()
這樣,就可以使用 import MySQLdb 了,其他方法與MySQLdb一樣