导入utf-8 mysqldump到latin1数据库 [英] import utf-8 mysqldump to latin1 database

查看:54
本文介绍了导入utf-8 mysqldump到latin1数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在utf8中有一个phpnuke网站的转储文件.我正在尝试在新服务器上重新打开该站点.但是nuke使用latin1.我需要一种使用此utf-8转储文件创建latin1数据库的方法.我尝试了所有我能想到的.iconv,mysql替换,php替换...

I have a dump file of a phpnuke site somehow in utf8. I'm trying to reopen this site on a new server. But nuke uses latin1. I need a way to create a latin1 database using this utf-8 dump file. I tried everything I could think of. iconv, mysql replace, php replace...

推荐答案

在转储的开始处添加 SET NAMES'utf8'; 语句.这将向MySQL指示它将要接收的命令在UTF8中.它将以表中当前设置的任何字符集存储数据;在这种情况下,如果您的数据库位于latin1中,则数据将存储在latin1中.

Add the SET NAMES 'utf8'; statement at the beginning of your dump. This will indicate to MySQL that the commands it is about to receive are in UTF8. It will store the data in whatever character set your tables are currently set in; in this case if your database is in latin1, data will be stored in latin1.

来自 http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html :

SET NAMES指示客户端将使用什么字符集将SQL语句发送到服务器.因此,SET NAMES'cp1251'告诉服务器,将来来自此客户端的传入消息使用字符集cp1251."它还指定服务器用于将结果发送回客户端的字符集.(例如,它表示使用SELECT语句时要用于列值的字符集.)

SET NAMES indicates what character set the client will use to send SQL statements to the server. Thus, SET NAMES 'cp1251' tells the server, "future incoming messages from this client are in character set cp1251." It also specifies the character set that the server should use for sending results back to the client. (For example, it indicates what character set to use for column values if you use a SELECT statement.)

最后一件事是,与utf8相比,latin1的可用字符要少得多.除西欧语言外,其他任何数据都将丢失.

One last thing is that latin1 has much less characters available than utf8. For anything other than the western European languages, you will lose data.

例如,假设列 test 为latin1.第一个条目将正确显示(法语口音在latin1之内);但是韩文的第二个条目将显示为问号.

For instance, assuming column test is latin1. The first entry will appear correctly (the French accent is within latin1); however the second entry in Korean will show as question marks.

SET NAMES 'utf8';
INSERT INTO TESTME(test) VALUES ('Bienvenue sur Wikipédia');
INSERT INTO TESTME(test) VALUES ('한국어 위키백과에 오신 것을 환영합니다!');

这篇关于导入utf-8 mysqldump到latin1数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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