背景:
使用pymysql鏈接mysql數據庫設置utf8編碼中文顯示?號
最後通過使用MySQLdb模塊鏈接mysqsl數據庫解決中文顯示亂碼的問題
import MySQLdb
鏈接數據庫
db = MySQLdb.connect(host='127.0.0.1',
db='tmp_db',
user='root',
password='123456',
charset='utf8',
)
cursor = db.cursor()
sql = """select country from country_code limit 10;
"""
cursor.execute(sql)
cursor.fetchall()
輸出結果