读书人

解决amazon RDS 出现“Illegal mix of

发布时间: 2012-09-10 11:02:32 作者: rapoo

解决amazon RDS 出现“Illegal mix of collations (latin1_swedish_ci,IMPLICIT)”的解决办法

今天遇到一个问题,我把数据库从EC2上安装的postgres替换为了amazon提供的RDS,之后在保存中文的时候出现错误:

Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE)


出现这个问题的原因是因为RDS的mysql字符集编码是latin。

因为RDS的一些安全性策略,不允许使用本地mysql workbench连接到数据库,所以只能通过EC2的机器连接过去修改字符集编码


具体操作如下:

1. 设置EC2的SG,开放mysql的端口3306

2.设置RDS的SG,允许EC2的机器连接

3. 用putty登录EC2

4.安装python 的mysql包:

>>> from django.db import connection>>> cursor = connection.cursor()>>> cursor.execute('SHOW TABLES')>>> results=[]>>> for row in cursor.fetchall(): results.append(row)>>> for row in results: cursor.execute('ALTER TABLE %s CONVERT TO CHARACTER SET utf8 COLLATE     utf8_general_ci;' % (row[0]))

无需重启mysql,再次输入中文,一切正常 :)


读书人网 >Web前端

热点推荐