How to change the default collation of a table?

前端 未结 4 1474
说谎
说谎 2020-11-30 16:21
create table check2(f1 varchar(20),f2 varchar(20));

creates a table with the default collation latin1_general_ci;

alte         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 16:55

    To change the default character set and collation of a table including those of existing columns (note the convert to clause):

    alter table  convert to character set utf8mb4 collate utf8mb4_unicode_ci;
    

    Edited the answer, thanks to the prompting of some comments:

    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

    and

    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

提交回复
热议问题