MySQL 5 的 UTF8 问题

2021-12-27 00:00:00 utf-8 encoding mysql phpmyadmin

我正在将我的 WordPress 博客和 phpBB 论坛迁移到一个新的托管服务器.我正在使用 phpMyAdmin 从上一个站点的数据库中导入 SQL 脚本.

I'm migrating my WordPress blog and phpBB Forum into a new hosting server. I am using phpMyAdmin to import the SQL script from the database in the previous site.

当我用 Kate 打开 .sql 脚本时,它说它使用 UTF8 作为编码.我在新服务器导入sql的时候,在phpMyAdmin里面有选择编码的选项,这里默认选择utf8.

When I open the .sql script with Kate, it says it uses UTF8 as encoding. When I import the sql in the new server, I have the option in phpMyAdmin to choose the encoding, where utf8 is selected by default.

然而,当我完成导入数据库时​​,我直接在phpMyAdmin中阅读了帖子文本,并看到了诸如é",ñ"等未被解释"并被替换为奇怪字符的字符插入.

Still, when I finish importing the database, I read the posts text directly in phpMyAdmin, and see characters such as "é", "ñ", etc. which haven't been "interpreted" and been replaced with weird characters insted.

我可以看到我的 WordPress 安装也不起作用.显然这个编码有问题,但我认为问题出在 MySQL 数据库或 phpMyAdmin 而不是 WordPress.

I can see my WordPress installation is not working also. Apparently there's a problem with this encoding thing, but I think the problem is in the MySQL database or phpMyAdmin and not WordPress.

MySQL 的版本几乎相同,即 MySQL 5,但版本不同.还有,迁移论坛数据库的时候没有问题,所以这更奇怪......

The versions of MySQL are practically the same, MySQL 5, but a different revision. Also, there was no problem when migrating the forum database, so this is even stranger...

我不知道如何解决这个问题...欢迎提出任何想法.

I'm lost as to how to fix this... Any ideas are welcome.

推荐答案

您是否尝试添加

SET NAMES 'utf8';

到你的 sql 转储?

to your sql dump?

utf8 或一般编码的事情是,为了成功,您必须确保:

The thing with utf8 or encodings in general is that in order to be successfull, you have to make sure that:

  • 文件采用utf8编码,没有签名
  • mysql 服务器的默认编码设置为 utf8
  • 连接是 utf8(这就是您将 SET NAMES 'utf8' 放入 sql 文件的原因).
  • 所有表和列都有正确的编码和字符集
  • 你所有的网络文件也必须是 utf8 编码的.仅添加正确的标题是行不通的.您必须打开文件,检查编码是否为 utf8,如果不是,则剪切所有内容,将编码更改为 utf8 并将所有内容粘贴回去.如果您只是更改编码并保存文件,它不起作用!

相关文章