latin-1 to utf-8 database

2019-02-06 22:17发布

I have a database that is uft8_general_ci, only problem is up until this point an application coded by a previous developer seems to have been working with the database in latin-1.

I have since changed how the app uses the database and can now store an umlaut as an umlaut instead of ü. The problem now is that the application reads the previously existing data from the database as (example) 'Süddeutsche' instead of 'Süddeutsche'.

Is there anyway to convert the data inside the database from one format to the other?

Regards

Edit:

ALTER TABLE TableName MODIFY ColumnName ColumnType CHARACTER SET latin1;
ALTER TABLE TableName MODIFY ColumnName ColumnType CHARACTER SET binary;
ALTER TABLE TableName MODIFY ColumnName ColumnType CHARACTER SET utf8;

This worked for me.

3条回答
走好不送
2楼-- · 2019-02-06 22:18

http://blog.hno3.org/2010/04/22/fixing-double-encoded-utf-8-data-in-mysql/

Using what is listed here has fixed all my problems. I used this with my live data and have had no issues!

查看更多
Rolldiameter
3楼-- · 2019-02-06 22:24

You could try SET NAMES to let the Database talk in latin-1 with your application while storing in utf-8 or you will need to convert all previous Datasets to utf-8-Strings

查看更多
放荡不羁爱自由
4楼-- · 2019-02-06 22:32

try

ALTER DATABASE your_db DEFAULT CHARACTER SET = 'utf8' COLLATE 'utf8_unicode_ci';

and

ALTER TABLE a CONVERT TO CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';

ALTER TABLE b CONVERT TO CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
ALTER TABLE c CONVERT TO CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';

don't forget to replace the 'ß':

UPDATE a SET field_1 = REPLACE(field_1, 'ß', 'ss') WHERE label LIKE '%ß%';
查看更多
登录 后发表回答