So you want to run MySQL with UTF-8 enabled by default...
The default character set for MySQL is Latin1. This is kind of silly because the whole world is indeed moving towards UTF-8. But you can change this! Because really, you most definitely want to support any and every language in the world. Or at least you want the potential to do that.
Are there drawbacks to working the database in UTF-8? There are only two drawbacks that I've encountered. The first is that a unique index on a UTF-8 column is limited to 333 characters. The second is that you have to configure UTF-8 onto every client with which you connect to the database. But otherwise it's really to use and set up.
All you really need to do is edit your my.cnf file. This file is in different places on different Unix systems and Windows systems. On Debian, for example, this is located in /etc/mysql and on Fedora it is located in /etc.
To make your clients connect and send UTF-8 data, set this in the [client] section:
You want to make MySQL communicate in UTF-8 and store things in UTF-8. To have the server do that, add this to the [mysqld] section:default-character-set = utf8
Just a few other things that you probably want to add. For example, if you are going to use InnoDB it will create one giant file. This makes it slow to alter tables, add new tables, back things up, etc. You want to make InnoDB function like MyISAM: one file per table. To do that, add this to [mysqld].character-set-server = utf8
If you expect to insert LOBs into the database, you will probably want to set this in the [mysqld] section:innodb_file_per_table
Of course if you do insert a LOB, you will have some trouble backing up the database with mysqldump unless you add this to the [mysqldump] section of my.cnf.max_allowed_packet = 1024M
You might also need to add --hex-blob as an option to mysqldump to properly get LOBs saved in a dump file.max_allowed_packet = 1024M
And those are changes that I make to MySQL before starting it up for the first time.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Any instructions provided in this essay are provided as-is with no warranty whatsoever and the author bears no liability resulting from any and all uses of this work. Use at your own risk.
© Copyright 2002 - 2012 Paul Lockaby. All rights reserved.