如何更改表的默认排序规则? [英] How to change the default collation of a table?
问题描述
create table check2(f1 varchar(20),f2 varchar(20));
使用默认排序规则latin1_general_ci
;
alter table check2 collate latin1_general_cs;
show full columns from check2;
将列的各个排序规则显示为"latin1_general_ci".
shows the individual collation of the columns as 'latin1_general_ci'.
那么alter table命令的作用是什么?
Then what is the effect of the alter table command?
推荐答案
要更改表的默认字符集和排序规则,包括现有列的(请注意转换为子句):
To change the default character set and collation of a table including those of existing columns (note the convert to clause):
alter table <some_table> convert to character set utf8mb4 collate utf8mb4_unicode_ci;
编辑了答案,这要归功于一些评论的提示:
Edited the answer, thanks to the prompting of some comments:
应避免推荐utf8.它几乎从来不是您想要的,并且经常导致意想不到的混乱. utf8字符集与UTF-8不完全兼容.如果需要UTF-8,则需要utf8mb4字符集. – Rich Remer 18年3月28日在23:41
Should avoid recommending utf8. It's almost never what you want, and often leads to unexpected messes. The utf8 character set is not fully compatible with UTF-8. The utf8mb4 character set is what you want if you want UTF-8. – Rich Remer Mar 28 '18 at 23:41
和
这似乎很重要,很高兴我阅读了评论并感谢@RichRemer. Nikki,我认为您应该在答案中进行修改,以考虑得到多少意见.在这里看到 https://dev.mysql.com/doc /refman/8.0/en/charset-unicode-utf8.html 和此处 MySQL吗? – Paulpro 3月12日在17:46
That seems quite important, glad I read the comments and thanks @RichRemer . Nikki , I think you should edit that in your answer considering how many views this gets. See here https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8.html and here What is the difference between utf8mb4 and utf8 charsets in MySQL? – Paulpro Mar 12 at 17:46
这篇关于如何更改表的默认排序规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!