MySQL 5 的 UTF8 问题

发布于 2024-07-09 06:43:07 字数 478 浏览 3 评论 0原文

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

当我用 Kate 打开 .sql 脚本时,它说它使用 UTF8 作为编码。 当我在新服务器中导入sql时,我可以在phpMyAdmin中选择编码,其中默认选择utf8。

尽管如此,当我完成导入数据库时​​,我直接在 phpMyAdmin 中读取帖子文本,并看到诸如“é”、“ñ”等字符尚未被“解释”并被插入的奇怪字符替换。

我可以看到我的 WordPress 安装也无法正常工作。 显然这个编码有问题,但我认为问题出在 MySQL 数据库或 phpMyAdmin 而不是 WordPress。

MySQL 的版本实际上是相同的,即 MySQL 5,但版本不同。 另外,迁移论坛数据库时没有问题,所以这更奇怪......

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

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.

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.

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.

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

↘紸啶 2024-07-16 06:43:07

您是否尝试过添加

SET NAMES 'utf8';

到您的 sql 转储中?

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

  • 文件编码为 utf8,没有签名
  • mysql 服务器的默认编码设置为 utf8
  • 连接是 utf8 (这就是为什么您将将名称“utf8”设置到您的 sql 文件中)。
  • 所有表和列都有正确的编码和字符集,
  • 所有 Web 文件也必须采用 utf8 编码。 仅添加正确的标头是行不通的。 您必须打开文件,检查编码是否为 utf8,如果不是,则剪切所有内容,将编码更改为 utf8,然后将所有内容粘贴回来。 如果您只是更改编码并保存文件,这是行不通的!

Have you tried adding

SET NAMES 'utf8';

to your sql dump?

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

  • the file is encoded utf8 without signature
  • the default encoding of the mysql server is set to utf8
  • the connection is utf8 (that's why you put SET NAMES 'utf8' into your sql-file).
  • all tables and columns have the right encoding and charset
  • all your webfiles have to be utf8 encoded as well. And it doesn't work to just add the correct header. You have to open the file, check if the encoding is utf8, if not, cut everything, change the encoding to utf8 and paste everything back. It doesn't work, if you just change the encoding and save the file!
仄言 2024-07-16 06:43:07

非常感谢你的回答。 我找到了解决方案,我觉得以前没有意识到这一点真的很愚蠢。 一切都应该工作正常:

-文件是用 utf8 编码的
-表是用utf8声明的:

SET character_set_client = utf8;

-MySQL server was configured with utf8
Etc.

我一开始没有意识到我正在使用 cPanel 备份向导中的数据库备份。 当我意识到这一点时,我在旧服务器上使用 phpMyAdmin 导出数据库,将其导入到新服务器中,然后问题就解决了。

phpMyAdmin 比 cPanel 更好地理解 phpMyAdmin :P 显然 cPanel 导出了脚本,以便与 cPanel 本身一起导入。 这很可能也有效,但我更信任 phpMyAdmin。

不过非常感谢您的回答。

Thanks a lot for your answers. I found the solution, and I feel really dumb not to have realized it before. Everything was supposed to work fine:

-File was encoded with utf8
-Tables were declared with utf8:

SET character_set_client = utf8;


-MySQL server was configured with utf8
Etc.

What I didn't realize in the first place is I was using a database backup from cPanel's backup wizard. As soon as I realized this, I used phpMyAdmin on the old server to export the database, imported it in the new server, and presto, problem fixed.

phpMyAdmin understands phpMyAdmin better than cPanel :P Apparently cPanel exports the script for it to be imported with cPanel itself. This would have most probably worked as well, but I trust phpMyAdmin better.

Thanks a lot for your answers though.

听风吹 2024-07-16 06:43:07

我刚刚遇到了同样的问题,因为我与它搏斗了大约一个小时,它破坏了我的许多网站,我想我应该看看是否有其他人在努力解决这个问题并发布解决方案:解决方案很简单就是指定导入时的导入字符集。

如果您可以通过 SSH 访问主机,请首先再次将所有表再次删除到新数据库中,然后在 SSH 会话中运行此命令(假设您的旧转储文件是 olddatabase.dump.sql):

$ mysql -h 主机 -u 用户名 -p 密码 --default-character-set=utf8 数据库 旧数据库.dump.sql
(将主机、用户名、密码和数据库替换为适当的值)

这是解决问题的最简单、最直接的方法。

I just ran across the same problem, since I wrestled with it for about an hour and it broke many of my sites, I figured I'd look and see if anyone else was struggling with it and post a solution: The solution quite simply is to specify the import character set on import.

If you have SSH access to your host, first drop all your tables again in new database again, then run this command in the SSH session (assuming your old dump file is olddatabase.dump.sql):

$ mysql -h host -u username -p password --default-character-set=utf8 database < olddatabase.dump.sql
(replace host, username, password, and database with appropriate values)

This is the simplest and most straightforward way to solve the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文