UTF-8 and MySQL can be tricky. Sometimes the problem isn’t noticed right away. Here is how I solved my recent encounter with UTF-8 issues and MySQL.
I’ve just fixed an issue where values were not properly being stored as UTF-8 in MySQL. The problem turned out to be the need of a few
my.cnf config settings. I don’t claim to know much about the inner workings of MySQL, simply because that is not where most of my time is spent. But I wanted to share the solution that worked in my particular case:
MySQL version: 5.1.41 (Ubuntu Linux)
[mysqld] init_connect='SET collation_connection = utf8_unicode_ci; SET NAMES utf8;' default-character-set=utf8 character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake
Tip On Ubuntu I created a utf8 config file at
/etc/mysql/conf.d/utf8.cnf with the above contents and simply restarted mysql using
sudo service mysql restart.
I had problems when I did not include
skip-character-set-client-handshake. Adding it along with everything else fixed my UTF8 issues.