UTF8 encoding with Ruby Sequel (and MySQL)
Just a quick note to self. If you need to store Unicode and are using Sequel, make sure you:
- Create the database with a default charset of UTF8:
CREATE DATABASE my_db DEFAULT CHARSET utf8;. I think then any tables you create uses the default charset of utf8 unless otherwise specified. - Pass an
:encodingoption to Sequel's MySQL adapter:DB = Sequel.mysql 'my_db', :user => 'root', :password => '', :host => 'localhost', :encoding => 'utf8'
The Sequel documentation and wiki were quite unhelpful but reading code (see the connect method definition) always helps!