我们在整个应用中使用utf8_bin
归类,因为许多列可以包含AaAaa
和AAAAA
等条目,并且需要区分大小写。将来,我们可能只会将这些列切换为ut8_bin
整理,但就目前而言,我们只是以这种方式设置所有表格。
但是,如下面的示例输出所示,collection
表的排序规则以某种方式设置为latin1_swedish_ci
而不是utf8_bin
。
SHOW TABLE STATUS FROM codepen;
+---------------------------+--------+---------+------------+---------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-------------------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+---------------------------+--------+---------+------------+---------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-------------------+----------+----------------+---------+
| collections | InnoDB | 10 | Compact | 19939 | 79 | 1589248 | 0 | 688128 | 4194304 | 28835 | 2014-03-15 03:54:01 | NULL | NULL | latin1_swedish_ci | NULL | | |
我的问题是,如果我们运行像
这样的查询alter table collections convert to character set utf8 collate utf8_bin;
我们是否存在任何数据丢失的风险?
此外,该表非常小。我们可以在没有停机的情况下进行此转换吗?
mysql> SELECT table_name AS "Table",
-> round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
-> FROM information_schema.TABLES
-> WHERE table_schema = "codepen"
-> AND table_name = "collections";
+-------------+------------+
| Table | Size in MB |
+-------------+------------+
| collections | 2.17 |
+-------------+------------+
如果load在这个问题上有所不同,我们每秒会做125次连接查询。