What will happen to existing data if I change the collation of a column in MySQL?(如果我更改 MySQL 中列的排序规则,现有数据会发生什么情况?)
问题描述
我正在使用 MySQL 数据库服务器运行生产应用程序.我忘记将列的排序规则从 latin 设置为 utf8_unicode,这会导致在保存到包含多语言数据的列时出现奇怪的数据.
I am running a production application with MySQL database server. I forget to set column's collation from latin to utf8_unicode, which results in strange data when saving to the column with multi-language data.
我的问题是,如果我现在将排序规则更改为 utf8_unicode,我现有的数据会怎样?它会破坏或破坏现有数据,还是会保留数据,但新数据将按原样保存为utf8?
My question is, what will happen with my existing data if I change my collation to utf8_unicode now? Will it destroy or corrupt the existing data or will the data remain, but the new data will be saved as utf8 as it should?
我将使用 phpMyAdmin 网络客户端进行更改.
I will change with phpMyAdmin web client.
推荐答案
在 MySQL 5.1 中运行快速测试,将 VARCHAR 列设置为 latin1_bin 我插入了一些非拉丁字符
Running a quick test in MySQL 5.1 with a VARCHAR column set to latin1_bin I inserted some non-latin chars
INSERT INTO Test VALUES ('英國華僑');
我选择了它们并得到了垃圾(正如预期的那样).
I select them and get rubbish (as expected).
SELECT text from Test;
给予
text
????
然后我将列的排序规则更改为 utf8_unicode 并重新运行 SELECT 并显示相同的结果
I then changed the collation of the column to utf8_unicode and re-ran the SELECT and it shows the same result
text
????
这就是我所期望的 - 它将保留数据,而数据将仍然是垃圾,因为在插入数据时,该列丢失了额外的字符信息,只是插入了一个 ?对于每个非拉丁字符,没有办法 ????再次成为英国华侨.
This is what I would expect - It will keep the data and the data will remain rubbish, because when the data was inserted the column lost the extra character information and just inserted a ? for each non-latin character and there is no way for the ???? to again become 英國華僑.
您的数据将保留在原处,但不会被修复.
Your data will stay in place but it won't be fixed.
这篇关于如果我更改 MySQL 中列的排序规则,现有数据会发生什么情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果我更改 MySQL 中列的排序规则,现有数据会发生什么情况?
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 无法解决整理冲突 2021-01-01
