What will happen to existing data if I change the collation of a column in MySQL?

前端 未结 5 488
无人及你
无人及你 2021-01-12 02:37

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

5条回答
  •  隐瞒了意图╮
    2021-01-12 03:20

    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;
    

    gives

    text
    ????
    

    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.

提交回复
热议问题