Rails + MySQL: Case-Sensitive strings in your database

When using Rails + MySQL, you’ll find that normal string (or varchar(255)) fields are case insensitive. This can be quite a nuisance, but it’s easy to resolve. You need to set your table to the utf8_bin collation. By using the binary variant, you’re basically enabling case sensitivity.

create_table :posts, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin' do |t|
  t.string :title, :limit => 100
end

That’s all. The title field is now case sensitive.

  • Twitter
  • Digg
  • del.icio.us
  • DZone
  • Reddit
  • email

2 Responses to “Rails + MySQL: Case-Sensitive strings in your database”

  1. Ed Lebert says:

    I’m disappointed in MySQL. Case-sensitivity should be the default in everything.

  2. database says:

    database…

    Today Monday I found your article How to make a brilliant mysql forum database from scratch …. Just curious: on what bases do you conclude your findings?…

Leave a Reply