MySQL encoding and converting databases to UTF8
I found a great tip over ath the fingertip blog: Ruby and MySQL encoding flakiness
It details some shady behavior related to UTF8 / MySQL encoding and Rails. The tip worked fine but I found that my production Rails database was still in latin1 even though everything else in my app is setup for UTF8.
So after some searching I found a relatively quick way to convert your MySQL database into UTF8 encoding (Though there might be a easier method.) Basically using the following tasks:
1.) Dump the DB:
mysqldump –user=username –password=password –default-character-set=latin1 –skip-set-charset dbname > dump.sql
2.) Replace all latin1 instances with utf8:
sed -r ’s/latin1/utf8/g’ dump.sql > dump_utf.sql
3.) Delete the old DB, create a new one in UTF8:
mysql –user=username –password=password –execute=”DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;”
4.) Load the dump into the new DB:
mysql –user=username –password=password –default-character-set=utf8 dbname < dump_utf.sql
Check out the MySQL database to UTF8 how-to here
.
Posted on February 21, 2007
Filed Under Business, Daily Thoughts, Design, Hosting, PHP/MySQL, Productivity, Ruby on Rails, Startup, SugarStats, Tech, Web
Related Posts:
-
MySQL Query Analyzer Rails Plugin Released
Securing MySQL on OS X
Rails Multi-DB Connection Pool Management Goodness
Show my Ruby Gems
Rake MySQL Database Backup Task
One-click Ruby on Rails OS X development solution
Comments
3 Responses to “MySQL encoding and converting databases to UTF8”
Leave a Reply

Another Day, Another Post…
[...] Normally I don’t write about other peoples blogs, but this one really caught my eye: [...]...
[...] If you need to convert your database tables this article at marstononline.com might be helpful. [...]
[...] original link [...]