I have a MySQL database, full of data, with collation = latin1 - default collation
.
If I change that collation to utf8 - default collation
, a superset of the collation above,
would there be any corruption in the existing data?
I have a MySQL database, full of data, with collation = latin1 - default collation
.
If I change that collation to utf8 - default collation
, a superset of the collation above,
would there be any corruption in the existing data?
Your data will not be corrupted, but you must take care to update the collation of all tables and columns and not just change the default collation of the database as this would only apply to new tables. If you do not alter all existing tables you might encounter some odd behaviour when running queries where data are compared.
I would recommend that you run the following queries as taken from David Whittaker's answer
Heres how to change all databases/tables/columns. Run these queries and they will output all of the subsequent queries necessary to convert your entire schema to utf8. Hope this helps!
-- Change DATABASE Default Collation
SELECT DISTINCT concat('ALTER DATABASE `', TABLE_SCHEMA, '` CHARACTER SET utf8 COLLATE utf8_unicode_ci;')
from information_schema.tables
where TABLE_SCHEMA like 'database_name';
-- Change TABLE Collation / Char Set
SELECT concat('ALTER TABLE `', TABLE_SCHEMA, '`.`', table_name, '` CHARACTER SET utf8 COLLATE utf8_unicode_ci;')
from information_schema.tables
where TABLE_SCHEMA like 'database_name';
-- Change COLUMN Collation / Char Set
SELECT concat('ALTER TABLE `', t1.TABLE_SCHEMA, '`.`', t1.table_name, '` MODIFY `', t1.column_name, '` ', t1.data_type , '(' , t1.CHARACTER_MAXIMUM_LENGTH , ')' , ' CHARACTER SET utf8 COLLATE utf8_unicode_ci;')
from information_schema.columns t1
where t1.TABLE_SCHEMA like 'database_name' and t1.COLLATION_NAME = 'old_charset_name';