V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dddd
V2EX  ›  Python

python3.4+tornado 查询 mysql 数据库出现错误,见下文

  •  1
     
  •   dddd · 2014-05-26 22:04:22 +08:00 · 4729 次点击
    这是一个创建于 3645 天前的主题,其中的信息可能已经有所发展或是发生改变。
    pymysql.err.InternalError: (1267, "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='")

    如下语句创建表
    create table members(name varchar(40) not null primary key, password varchar(40) not null, question varchar(100) not null, answer varchar(100) not null);

    查询语句,name是中文字符
    cursor.execute("SELECT name FROM members WHERE name='%s'" % name)

    用pymysql-0.6.2连接数据库,后面的charset="utf8"没加出现另一个错误
    self.db = pymysql.connect("localhost","root","DXC","demo",charset="utf8")
    如下:
    UnicodeEncodeError: 'latin-1' codec can't encode characters in position 37-40: ordinal not in range(256)

    在华莽用户组也发了一遍https://groups.google.com/forum/#!topic/Python-cn/qVK95FAH0JI
    3 条回复    2014-05-27 10:09:28 +08:00
    openroc
        1
    openroc  
       2014-05-26 22:29:42 +08:00
    mysql create database时是用的utf8吗?
    dddd
        2
    dddd  
    OP
       2014-05-26 23:36:34 +08:00
    @openroc 解决了,mysql改为了utf8编码,但是又一个问题出现了,tornado的中文cookie乱码,怎么破???
    cute
        3
    cute  
       2014-05-27 10:09:28 +08:00
    urlencode啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   950 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 22:24 · PVG 06:24 · LAX 15:24 · JFK 18:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.