使用Python对MySQL数据库操作时,当插入中文数据时,会报错如下:'latin-1' codec cannot encode characters.这个是由于字符编码的问题引起的.在确保MySQL安装时设置为uft8编码,表的建立使用utf8编码,程序中只需要在开头写好:
#-*- coding: utf-8 -*-,
并在设定连接字符串时候写清使用utf8就可以了
conn=MySQLdb.connect(host="locahost",user="root",passwd="123",db="test",charset="utf8").

可参考:http://www.sou5.cn/archives/253.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-09
  • 2021-11-25
  • 2021-09-21
  • 2022-12-23
  • 2021-07-30
相关资源
相似解决方案