开发者

MySQL charset conversion

I have a database in which all text fields and tables have 'utf8' specified explicitly as default character set, however data in this database is stored as 'cp1257'. I can display symbols only when I use SET NAMES 'cp1257' or \C cp1257. Trying to display them without those instructions fails, because it tries to fetch data as 'utf8' (?). What could I do to get all data (perhaps a backup) of database as 'cp1257' 开发者_如何学Cand put it back as valid 'utf8' ?


You need to convert them first to binary field and then set the field as cp1257. This way MySQL will know in which charset the field is stored:

ALTER TABLE CHANGE `field` `field` BLOB;
ALTER TABLE CHANGE `field` `field` TEXT CHARACTER SET 'cp1257';

If you want to change way how data are stored, you can now convert the field to any charset (MySQL will do the conversion of data in this step):

ALTER TABLE CHANGE `field` `field` TEXT CHARACTER SET 'utf8';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜