新聞中心
通過python查詢數(shù)據(jù)庫中數(shù)據(jù)時(shí),數(shù)據(jù)匯呈現(xiàn)亂碼,只需要在連接串中指定數(shù)據(jù)編碼就可以如“utf8”、“GBK”即可:

成都創(chuàng)新互聯(lián)公司是由多位在大型網(wǎng)絡(luò)公司、廣告設(shè)計(jì)公司的優(yōu)秀設(shè)計(jì)人員和策劃人員組成的一個(gè)具有豐富經(jīng)驗(yàn)的團(tuán)隊(duì),其中包括網(wǎng)站策劃、網(wǎng)頁美工、網(wǎng)站程序員、網(wǎng)頁設(shè)計(jì)師、平面廣告設(shè)計(jì)師、網(wǎng)絡(luò)營銷人員及形象策劃。承接:網(wǎng)站設(shè)計(jì)制作、成都做網(wǎng)站、網(wǎng)站改版、網(wǎng)頁設(shè)計(jì)制作、網(wǎng)站建設(shè)與維護(hù)、網(wǎng)絡(luò)推廣、數(shù)據(jù)庫開發(fā),以高性價(jià)比制作企業(yè)網(wǎng)站、行業(yè)門戶平臺(tái)等全方位的服務(wù)。
import pymySQL
db=pymysql.connect(host="localhost",user="root",password="root",database="school_schema",charset="GBK")
cursor=db.cursor()
sqlstr="SELECT * FROM school_schema.course;"try:
cursor.execute(sqlstr)
courses=cursor.fetchall()except:
print("數(shù)據(jù)讀取錯(cuò)誤")else:
print(courses)
db.close()pymysql.Connect()參數(shù)說明:
-
host(str): MySQL服務(wù)器地址
-
port(int): MySQL服務(wù)器端口號(hào)
-
user(str): 用戶名
-
passwd(str): 密碼
-
db(str): 數(shù)據(jù)庫名稱
-
charset(str): 連接編碼
文章題目:創(chuàng)新互聯(lián)Python教程:python中進(jìn)行sql查詢出現(xiàn)亂碼怎么解決
文章來源:http://www.dlmjj.cn/article/ccejioj.html


咨詢
建站咨詢
