views:

21

answers:

2

Hi Everyone,

I have made a mistake when designing my application database several years ago and collation settings of my tables and table fields are mixed. Some of them are utf8_general_ci and some of them are utf8_unicode_ci.

This causes problems when joining tables with different collations. Now, I am planning to change collation settings and make them the same: utf8_unicode_ci. I will be running these two SQL queries on all my tables.

ALTER TABLE  `table1` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE  `table1` CHANGE  `Action`  `Action` VARCHAR( 250 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;

My question is, does running these two SQL queries break any field values, especially the ones which contains accented characters? Or is it safe to run these two queries?

Looking forward to hear from you.

Thanks for your answers!

+1  A: 

Collation only affects how strings within a field are compared, not how they're stored. As far as you stay with utf8 encoding, you're safe.

Mchl
yup, this is correct. There are subtle sorting and comparison differences like german `ß`= `ss` and others, but no data will be changed. See http://dev.mysql.com/doc/refman/5.1/en/charset-unicode-sets.html for details
Pekka
Guys, please check this out (http://dev.mysql.com/doc/refman/5.1/en/charset-column.html) as Koteswasa mentions below. Thanks for your time.
TamTam
I stand corrected. Still within same encoding, switching collation is safe.
Mchl
+1  A: 

please refer mysql doc which talks about changing character set and collation

http://dev.mysql.com/doc/refman/5.1/en/charset-column.html

Its saying that - "If you use ALTER TABLE to convert a column from one character set to another, MySQL attempts to map the data values, but if the character sets are incompatible, there may be data loss."

--Cheers

Koteswara sarma
Thanks for your kind answer.
TamTam