Change the default MySql character encoding to UTF-8

note from Tue Aug 25, 2015

For some reason on most Ubuntu releases the MySql package as installed through apt-get sets the default encoding for latin1. You can happily run your RoR app this way for a long time, and maybe forever, until you have to save a curly quote or maybe even a "主頁" label somewhere, at which point you get 500 errors and everthing starts to complain that these characters are not latin1. Documentation on how to do this are on the msyql site here, but in short add these to the respective sections in your /etc/mysql/my.cnf. (Other distros will have this in a different location, like maybe /etc/my.cnf)

The following is for MySql 5.5, refer to the mysql docs to make sure they are the same for your version of MySql.

[client]

default-character-set=utf8

[mysqld]

collation-server = utf8_unicode_ci

init-connect='SET NAMES utf8'

character-set-server = utf8

[mysql]

default-character-set=utf8

Note that any databases and tables created before these configuration settings are put in will be in the default encoding. You will have to use an alternate method to convert those databases to utf8. I'll post how I did this in a subsequent post.

What I'm reading now

A friend recommended "The Little Schemer." The book sets out to teach good recursive thinking through the Scheme programming language. It's slow reading for me, but I am quite enjoying it. I'm learning quite a lot from it. Here's a link to it on Amazon where you can read more about it.

MySql Books

This book probably covers more that one would need for a typical RoR installation, but it has very handy info nonetheless.