Change MySQL table character set from latin1 to utf8

by

I have a table “t_user”, it’s character set is “latin1” when create it, and I want to save some unicode text at field “username”, but when I saved, the data is “????”, so I need to change character set from “latin1” to “utf8”.

I use

ALTER TABLE `t_user` CHARSET=utf8;

then I saved unicode data again, but still “????”.

I found that the character set of the field “username” is still “latin1”, so I droped field “username”,

ALTER TABLE `t_user` DROP COLUMN `username`;

and then create it again,

ALTER TABLE `t_user`
ADD COLUMN `username` VARCHAR(20) NULL;

the character set of the field “username” is “utf8” now, and the unicode data was saved correctly.

Some MySQL tools you can try: https://www.withdata.com/mysql/