UTF8 encoding with Ruby Sequel (and MySQL)

In: Ruby

15 Mar 2008

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 :encoding option 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!

Comments are closed.