Setting MySQL to Default to Unicode

When running unit tests in Django, I was getting a strange MySQL failure when attempting to insert non-ASCII Unicode characters into the database, for example:

Warning: Incorrect string value: '\xE2\x89\xA5 %' for column 'value' at row 1

What is happening is that Django creates a new schema from scratch for testing. This new schema picks up the MySQL defaults. All my test tables ended up with Latin-1 encoding instead of UTF-8 encoding.

I needed to change mysqld to default to unicode internally so Django will run unit tests involving correctly.

In /etc/my.cnf I added the following:



collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8

h/t stackoverflow

This entry was posted in Programming and tagged , , , , , , . Bookmark the permalink.

Leave a Reply