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 :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 & TrackBacks (Add yours)

The paper doll icon that precedes each comment is an idea conceived by Vanessa Tan.

There are no comments yet. Somebody say something!

You can subscribe to the RSS feed for comments on this post.

Post a comment

(required)

(required, but never displayed)


You can format your comments using XHTML. Your email address will not be displayed or used for nefarious purposes.

Only following tags are allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>