2

Today my database character set and collation is set to latin1. All of the tables in the database are however already set to DEFAULT CHARSET=utf8 and all data is utf8.

Is if it is safe to change character set and collation of the database to utf8?

Is it safe to also set the default settings in the my.cnf file with:

[client] default-character-set=utf8

[mysqld] default-character-set = utf8

A typical table in the database looks like this:

CREATE TABLE `tblpayment` (
    `paymentid` int(11) NOT NULL AUTO_INCREMENT,
    `userid` mediumint(9) DEFAULT NULL,
    `payed` enum('False','True') CHARACTER SET latin1 DEFAULT 'False',
    PRIMARY KEY (`paymentid`)
) ENGINE=InnoDB AUTO_INCREMENT=72803 DEFAULT CHARSET=utf8;

As you can see the enum "payed" is still using latin1 for some reason, however the rest of the table is utf8. Is it safe to change the CHARACTER SET of the enum to utf8 instead?

1 Answer 1

2

Setting the default character set and collation is completely safe. This will ensure that future DDL changes will use utf8, but will not affect existing columns that use latin1. Those will have to be converted to utf8. Make a backup of the data, because there are risks of data corruption (one example).

And for completeness, I will point out that adding the changes in the my.cnf will require a server restart.

2
  • Thanks! All data in the database is already converted (my tables where first created in latin1). But for some reason I must have forgotten about the enum('False','True') column. Is it safe to just switch these to utf8 too, without converting?
    – Martin
    Feb 24, 2012 at 8:06
  • @Martin sorry, I didn't see this. You should be able to set them to utf8, but just be ready with a backup (good practice)! Mar 2, 2012 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.