Home  >  Article  >  Database  >  Rails开发中的MySQL中文问题以及简单解决方式

Rails开发中的MySQL中文问题以及简单解决方式

WBOY
WBOYOriginal
2016-06-07 16:53:45799browse

Rails2.2.2对中文的支持是不错的,当然不仅仅是中文,所有多字节文字都能够很好得被支持。对于一个有很高本地化l10n和国际化i18n

Rails2.2.2对中文的支持是不错的,当然不仅仅是中文,所有多字节文字都能够很好得被支持。
对于一个有很高本地化l10n和国际化i18n需求的网站,多语言支持的实现方式很多,最常用的是采用gettext来实现。
在网页生成过程中,初学者最容易出问题的就是数据库连接的编码问题。最便捷的解决方式是采用utf8编码方式。
Rails应用中config/database.yml中可以在数据库段中设置encoding: utf8如下:

----------------
development:
adapter: mysql
encoding: utf8
database: project_development
pool: 5
username: root
password:
host: localhost
----------------

对于使用MySQL数据库的应用,只要设置/etc/my.cnf就可以保证正确的存取utf8数据了。
检查/etc/my.cnf文件,保证里面有如下两段内容,,如果没有则添加进去:

--------------
[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8
init_connect='SET NAMES utf8'
--------------
修改保存之后,重启服务器即可。

--
Fedora cc
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: .
------

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn