python連接mysql中文數據編碼


系統是win7 x64

Python 2.7.6的site.py里面編碼設定為 utf-8

py文件首行指定 #coding:utf-8

MySQL 5.5.38安裝時指定代碼為utf-8

 

peewee的連接數據庫代碼為:

 

[python]  view plain  copy
 
  1. db = MySQLDatabase(host = '127.0.0.1', user = 'root', passwd = '1', database = 'mz', charset = 'utf-8')  


不指定charset,會提示:插入的字符串不正確。

 

 

但是指定后,會提示如下錯:

super(Connection, self).set_character_set(charset)
peewee.OperationalError: (2019, "Can't initialize character set utf-8 (path: C:\
\mysql\\\\share\\charsets\\)")

 

偶爾搜到文章,他是亂碼。

試了一下,把utf-8改成utf8,結果就正常了。

 

在mysql的表看了一下,果然是:

 

在Win下,phton2.x 確實是編碼麻煩。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM