作者:白云飞羽_389 | 来源:互联网 | 2023-09-16 13:29
MySQL 编码是 latin1, rails 编码 utf8,如何把 rails 编码 utf8 转换成 latin1,解决中文乱码问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| 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 |