I found that utf-8 is the standard , but Mysql doesn't fully support utf-8(4bytes) .
Now here is my situation.开发者_开发技巧 My collation variables of mysql show latin1 but the encoding mechanism in "database.yml"(rails) is utf8 .
I have a database with around 20 tables and around 1k rows in each table. I am using Mysql 5.0 , ruby 1.8.7 and rails 3 .
I would like to support at least a few non printable charters. What would be the best option ?
- Should I change the whole database to utf-8 ( converting is painful and also mysql fully doesn't support utf-8).
- Should I change the encoding mechanism in "database.yml" to latin1 ( will the new setting be compatible with old data that is already stored ).
- Is there any other solution ?
Thank you.
I think that the :encoding field in database.yml is just what is used when creating a new database.
It won't break your app if you change this field
(in fact I think it won't do anything, unless you use rake db:create
)
I suggest, if your app is targeting anyone outside of the US or western europe you should be using utf8. I find it surprising that Ubuntu still ships with the default as latin1.
This may be "optimised" for space but causes a hassle for almost anyone with a client facing website.
There are various links on google for how to convert your database to UTF8 http://www.devcha.com/2008/03/convert-existing-mysql-database-from.html
something like
/* convert the default character set (used for new tables) */
ALTER DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
/* convert a specific table */
ALTER TABLE db_table CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
of course....
always back up your data, and try it out on a staging machine first
精彩评论