V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · May 26, 2014 · 5364 views
    This topic created in 4354 days ago, the information mentioned may be changed or developed.
    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 replies    2014-05-27 10:09:28 +08:00
    openroc
        1
    openroc  
       May 26, 2014
    mysql create database时是用的utf8吗?
    dddd
        2
    dddd  
    OP
       May 26, 2014
    @openroc 解决了,mysql改为了utf8编码,但是又一个问题出现了,tornado的中文cookie乱码,怎么破???
    cute
        3
    cute  
       May 27, 2014
    urlencode啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   974 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 89ms · UTC 20:34 · PVG 04:34 · LAX 13:34 · JFK 16:34
    ♥ Do have faith in what you're doing.