MySQLdb 是 Python 連接 MySQL 的經典驅動程式,採用 DB-API 2.0 介面。
import MySQLdb
conn = MySQLdb.connect(
host="localhost",
user="root",
passwd="123456",
db="test"
)
cursor = conn.cursor()
cursor.execute("select * from hard")
res = cursor.fetchall()
for x in res:
print(x)
cursor.close()
conn.close()

mysqlclient:MySQLdb 分支,支援 Python 3PyMySQL:純 Python 實作SQLAlchemy:ORM 框架