Ruby MySQL中文亂碼解決

來源:互聯網
上載者:User

這個要看三個地方

1.要確定你的mysql資料庫用的是什麼字元集,可以通過命令來看
mysql> show create database <你的資料庫名〉
可以用下面的命令建立一個gbk字元集的資料庫
mysql> create database xxxx default character set gbk

2.要確定你串連的的字串encode,比如在config/database.yml中
development:
adapter: mysql
database: collector
encoding: gbk
username: root
password:
host: localhost

3.在config/enviroment.rb 最後面增加一行
$KCODE="gbk"

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.