新手问题 MySQL 编码是 latin1, rails 编码 utf8,如何把 rails 编码 utf8 转换成 latin1,解决中文乱码问题

wozaijimo · 2015年03月03日 · 最后由 wozaijimo 回复于 2015年03月04日 · 2327 次阅读

mysql show variables like 'char%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+

select * from auto_brands; +----+--------+---------------------+---------------------+ | id | brand | created_at | updated_at | +----+--------+---------------------+---------------------+ | 1 | 本田 | 2011-06-02 05:49:43 | 2011-06-02 05:49:43 | | 2 | 宝马 | 2011-06-02 05:56:32 | 2011-06-02 05:56:32 | +----+--------+---------------------+---------------------+

database.yml development: adapter: mysql2 encoding: latin1 database: meiying_china_development pool: 5 username: root password: 123 socket: /var/run/mysqld/mysqld.sock

建议把环境统一成 UTF-8,这样比 latin1 <=> UTF-8 转换简单很多。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号