Bruce 的玩具間

my works and notes on ruby, rails, git, ubuntu linux, mac os x, etc...

Using utf8 encoding in Ruby with MySQL 5.1 and 5.5

| Comments

remember to require mysql gem first

    require "rubygems"  
    require 'mysql'  

with MySQL 5.1

db = Mysql.init


db.real_connect("localhost", "username", "password", "database")

with MySQL 5.5

db = Mysql.real_connect("localhost", "username", "password", "database")

db.charset = "utf8"

check the result:

puts db.character_set_name

If you got utf8, Congratulations!


comments powered by Disqus