Python:以UTF-8从Mysql查询数据

标签 python mysql

我使用 MySql 创建了数据库并将排序规则设置为 utf8_unicode_ci。 我在 python 程序中查询数据,如下代码

db = MySQLdb.connect(host="localhost",user="root",passwd="password",db="database",charset="utf8",use_unicode=True)
cur = db.cursor()
cur.execute("select `name` from car_park where p_id=1" )
rows=cur.fetchall()
print(rows)

但输出是 u'\u0e40\u0e14\u0e2d\u0e30\u0e21\u0e2d\u0e25\u0e4c'。 实际上数据库中的数据源是泰语。其他人已经通过 python 从泰语数据库或其他 UTF-8 查询数据,请帮忙。 谢谢。

最佳答案

rows 似乎是一个列表,您应该对其进行迭代。

for row in rows:
    print row

打印 unicode 对象不应出错。

关于Python:以UTF-8从Mysql查询数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33474221/

相关文章:

客户端的 MySQL/MariaDB 配置部分

php - 使用where子句计算sql数据的行数

mysql - 为 GCP CloudSQL 实例永久设置 utf8mb4

python - 如何使用 scikit-learn 对大文本数据进行分类?

mysql - 将 .NET 应用程序连接到 MySQL

python - 错误 : no viable alternative at input 'for' Python

python - Tree 的所有可能分区(簇)

php - SQL查询按给定日期范围对记录进行分组

python - 在 python 中导入文件与运行该文件一样吗?

python - Django + Anymail + Mailgun Webhook => META 中没有 HTTP_AUTHORIZATION