gpt4 book ai didi

mysql - Rails 3 ruby 1.9.2 : UTF-8 characters show garbled in console and view

转载 作者:行者123 更新时间:2023-11-29 14:43:13 28 4
gpt4 key购买 nike

我的数据库表有一列采用 utf8_general_ci 排序规则。

database.yml 的编码为:utf8

config/application.rb 有:config.encoding = "utf-8"

当我使用mysql命令行并直接查询它显示的字段时:3√5^2 = 5^(2/3); 5^(2/3) = 3√5^2

当我使用 Rails 控制台(或仅在 View 中显示)并输出它显示的字段时:3×5^2 = 5^(2/3); 5^(2/3) = 3×5^2

如您所见,sqrt 符号被弄乱了。

我做错了什么?

最佳答案

经过长时间的研究,我找到了解决方案。看起来有问题的列是双重编码的。它们曾经具有 Latin1 排序规则,但未正确转换为 UTF8。

建议的解决方案是将列更改为 BLOB,然后使用 UTF8 返回 TEXT,但不起作用:

ALTER TABLE t1 CHANGE c1 c1 BLOB;
ALTER TABLE t1 CHANGE c1 c1 TEXT CHARACTER SET utf8;

最终起作用的是:

mysqldump -uuser -ppassword --opt --quote-names --skip-set-charset --default-character-set=latin1 dbname1 table1 > dump.sql
mysql -uuser -ppassword --default-character-set=utf8 dbname1 < dump.sql

关于mysql - Rails 3 ruby 1.9.2 : UTF-8 characters show garbled in console and view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7561552/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com