MySQL 5 的 UTF8 问题
我正在将我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过添加
到您的 sql 转储中?
utf8 或编码的一般情况是,为了成功,您必须确保:
Have you tried adding
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:
非常感谢你的回答。 我找到了解决方案,我觉得以前没有意识到这一点真的很愚蠢。 一切都应该工作正常:
-文件是用 utf8 编码的
-表是用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:
-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.
我刚刚遇到了同样的问题,因为我与它搏斗了大约一个小时,它破坏了我的许多网站,我想我应该看看是否有其他人在努力解决这个问题并发布解决方案:解决方案很简单就是指定导入时的导入字符集。
如果您可以通过 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.