MySql varchar从Latin1更改为UTF8 [英] MySql varchar change from Latin1 to UTF8

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

问题描述

在mySql表中,我使用Latin1字符集在varchar字段中存储文本。由于我们的网站现在在更多的国家得到支持,我们需要支持UTF8。如果我将这些字段更改为UTF8会发生什么?是否安全,这样做或者会弄乱这些字段中的数据?在将字段更改为UTF8时,我需要考虑什么?

In a mySql table I'm using Latin1 character set to store text in a varchar field. As our website now is supported in more countries we need support for UTF8 instead. What will happen if I change these fields to UTF8 instead? Is it secure to do this or will it mess up the data inside these fields? Is it something I need to think about when changing the field to UTF8?

谢谢!

推荐答案

MySQL处理得很好:

MySQL handles this nicely:

CREATE TEMPORARY TABLE t1 (
  c VARCHAR(10)
) CHARACTER SET ="latin1";

INSERT INTO t1 VALUES ("æøå");
SELECT * FROM t1; # 'æøå'

ALTER TABLE t1 CHARACTER SET = "utf8";
SELECT * FROM t1; # 'æøå'

DROP TEMPORARY TABLE t1;

编辑:没有拉丁-1字符无法存储为utf-8,不应该得到任何dataloss

And there are no latin-1 characters that cannot be stored as utf-8, so you shouldn't get any dataloss

这篇关于MySql varchar从Latin1更改为UTF8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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