Steps
- Open the
my.cnffile. - Add the following lines to force UTF8 for all connections:
character_set_server=utf8
skip-character-set-client-handshake
- If you're interested in better performance, also add:
collation_server=utf8_general_ci
- If you're interested in better sorting order instead, add this line rather than the one above:
collation_server=utf8_unicode_ci
Frequently Asked Questions
Why force UTF8 at the MySQL server level instead of relying on each client? +
Because you can't control all the scripts that connect to your database (for instance the mysql command line or mysqldump), so forcing the server's collation and character set to UTF8 in my.cnf guarantees it regardless of the connecting client.
What two lines enable UTF8 for all connections in my.cnf? +
`character_set_server=utf8` and `skip-character-set-client-handshake`.
What's the difference between the two suggested collation settings? +
`collation_server=utf8_general_ci` is recommended for better performance, while `collation_server=utf8_unicode_ci` is recommended instead if better sorting order matters more.