Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2445379
  • 博文数量: 328
  • 博客积分: 4302
  • 博客等级: 上校
  • 技术积分: 5486
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-01 11:14
个人简介

悲剧,绝对的悲剧,悲剧中的悲剧。

文章分类

全部博文(328)

文章存档

2017年(6)

2016年(18)

2015年(28)

2014年(73)

2013年(62)

2012年(58)

2011年(55)

2010年(28)

分类: Mysql/postgreSQL

2013-08-31 15:19:38

在使用python storm的时候遇到如下错误:
  1.   File "/usr/local/lib/python2.6/dist-packages/storm/database.py", line 371, in _check_disconnect
  2.     return function(*args, **kwargs)
  3.   File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute
  4.     self.errorhandler(self, exc, value)
  5.   File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
  6.     raise errorclass, errorvalue
  7. _mysql_exceptions.OperationalError: (1267, "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='")
google了一下,有人说是字符集问题,解决方法如下。

1. 查看字符集设置

  1. mysql> SHOW VARIABLES LIKE 'character_set_%';
  2. +--------------------------+----------------------------+
  3. | Variable_name | Value |
  4. +--------------------------+----------------------------+
  5. | character_set_client | latin1 |
  6. | character_set_connection | latin1 |
  7. | character_set_database | latin1 |
  8. | character_set_filesystem | binary |
  9. | character_set_results | latin1 |
  10. | character_set_server | latin1 |
  11. | character_set_system | utf8 |
  12. | character_sets_dir | /usr/share/mysql/charsets/ |
  13. +--------------------------+----------------------------+
  14. 8 rows in set (0.00 sec)

  15. mysql> SHOW VARIABLES LIKE 'collation_%';
  16. +----------------------+-------------------+
  17. | Variable_name | Value |
  18. +----------------------+-------------------+
  19. | collation_connection | latin1_swedish_ci |
  20. | collation_database | latin1_swedish_ci |
  21. | collation_server | latin1_swedish_ci |
  22. +----------------------+-------------------+

2. 重设字符集

  1. set character_set_database =utf8;
  2. set character_set_results =utf8;
  3. set character_set_server =utf8;
  4. set character_set_system =utf8; --此处utf-8也可以
  5.  
  6. 然后执行:

  7. SET collation_server = utf8_general_ci
  8. SET collation_database = utf8_general_ci

3. 修改mysql的配置文件

vi /etc/my.cnf
  1. [mysqld]
  2. datadir=/var/lib/mysql
  3. socket=/var/lib/mysql/mysql.sock
  4. default-character-set=utf8

4. 更改已有数据库和表设置

点击(此处)折叠或打开

  1. //先修改数据库的字符集编码为:utf-8
  2. alter database <dbname> character set utf8;

  3. //修改该数据库下面的表的字符集编码为:utf-8
  4. alter table <tablename> character set utf8;

  5. //建库时设置字符集
  6. CREATE DATABASE [DB NAME] CHARACTER SET utf8 COLLATE utf8_unicode_ci;

  7. 查出数据库级的字符集。
  8. SHOW CREATE DATABASE db_name;

  9. 查出数据表的字符集。
  10. SHOW CREATE TABLE table_name;
  11. SHOW TABLE STATUS LIKE 'table_name'

  12. 查出数据列的字符集:
  13. DESCRIBE table_name;
  14. SHOW COLUMNS FROM table_name;
  15. SHOW CREATE TABLE table_name;

阅读(4152) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~