一般情况使用 ruby 直接链接 mysql ,默认编码则是 [b]latin1[/b]
如果mysql数据库编码是 utf-8 的话,通过上面代码插入的数据后,从mysql 客户端看到是乱码
问题很好解决,设置 ruby 客户端编码为 utf-8 就行了
参考 [url=http://wiki.a2hosting.com/index.php/UTF-8_MySQL_connections_with_Ruby]UTF-8_MySQL_connections_with_Ruby[/url]
require "mysql"
db = Mysql.new("localhost","username","password","database")
puts db.character_set_name
#output
#latin1
如果mysql数据库编码是 utf-8 的话,通过上面代码插入的数据后,从mysql 客户端看到是乱码
问题很好解决,设置 ruby 客户端编码为 utf-8 就行了
require "mysql"
db = Mysql.init
db.options(Mysql::SET_CHARSET_NAME,"utf8")
db.real_connect("localhost","username","password","database")
puts db.character_set_name
#output
#utf8
参考 [url=http://wiki.a2hosting.com/index.php/UTF-8_MySQL_connections_with_Ruby]UTF-8_MySQL_connections_with_Ruby[/url]