MySQL 5的UTF8问题 [英] UTF8 problem with MySQL 5

查看:136
本文介绍了MySQL 5的UTF8问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



仍然,当我完成导入数据库,我直接在phpMyAdmin中阅读帖子,并且看到诸如é,ñ等字符,这些字符未被解释,并被替换为奇怪的字符。



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



MySQL的版本几乎相同,MySQL 5,但不同的修订。此外,迁移论坛数据库时没有问题,所以这甚至是陌生人...



我失去了如何解决这个...任何想法欢迎您。

解决方案

您是否尝试添加

  SET NAMES'utf8'; 

到你的sql转储?



与utf8或编码一般的东西是,为了成功,你必须确保:




  • 该文件被编码utf8没有签名

  • mysql服务器的默认编码设置为utf8

  • 连接是utf8(这就是为什么你把SET NAMES'utf8' sql-file)。

  • 所有表和列都具有正确的编码和字符集

  • 所有的Web文件也必须是utf8编码的。而且只要添加正确的标题就行了。你必须打开文件,检查编码是否是utf8,如果没有,剪切所有内容,将编码更改为utf8并粘贴所有内容。它不起作用,如果您只是更改编码并保存文件!


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.

解决方案

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!

这篇关于MySQL 5的UTF8问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆