Python查詢資料庫,中文的結果顯示不出來

2022-04-25 01:49:58 字數 1521 閱讀 8139

表裡面的資料:

問題:查詢資料庫,返回結果不是中文可以,是中文的話就報錯unicodeencodeerror: 'gbk' codec can't encode character '\xd4' in position 5: illegal multibyte sequence

原始碼:

#

coding:utf-8

import

pymysql

conn =pymysql.connect(

host = '

localhost',

port = 3306,

user = '

root',

passwd = '

mysql',

db = '

cltest')

cur =conn.cursor()

sql = "

select id,status from cost_cl where id in (1,2)

"cur.execute(sql)

rows =cur.fetchall()

for dr in

rows:

print(dr)

這個是ok的

把查詢語句改成

尋找原因:

方法一:不適用我,我加入會報錯

方法二:也不行

方法三:

檢視我本機的mysql編碼格式

根據修改字元格式

此時依然沒用

方法四:加了gbk編碼,此時有返回結果,但是是亂碼

python多執行緒查詢資料庫並獲取返回結果

pip install dbutils 1.3 pip install mysqlclient 2.0.1 import time import threading import mysqldb import queue from mysqldb.cursors import dictcursor ...

mysql資料庫結構 Mysql資料庫的結構

1.mysql 版本 oracle mysql 8.0 mariadb perconadb 主流版本 mysql 5.6 5.6.36 5.38 5.6.40 mysql 5.7 5.7.18 5.7.20 5.7.22 企業版本選擇 6 12月之間的ga 2.mysql的體系結構 2.1 mysq...

python 查詢資料庫 匹配資料

usr bin env python coding utf 8 import re import argparse import os import commands import hashlib import subprocess import sys import shutil import m...