将utf-8 mysqldump导入latin1数据库

我在utf8中有一个phpnuke网站的转储文件.我正在尝试在新服务器上重新打开此站点.但是nuke使用了latin1.

我需要一种方法来使用这个utf-8转储文件创建一个latin1数据库.

我尝试了我能想到的一切. iconv,
mysql替换,php替换… 最佳答案 添加SET NAMES’utf8′;转储开头的声明.

这将向
MySQL表明它将要接收的命令是UTF8.

它会将数据存储在您当前设置的表中的任何字符集中;在这种情况下,如果您的数据库是latin1,数据将存储在latin1中.

http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html开始:

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.)

最后一点是,latin1的字符数比utf8少得多.对于除西欧语言之外的任何其他语言,您将丢失数据.

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

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