Ruby on Rails, UTF-8 & Heroku
I’m in the middle of moving some sites over from a self hosting VPS to Heroku and had some problems with the text encodings. Everything worked fine on the old site and on my local machine, but after a heroku db:push
(copying my local MySQL database to Heroku’s Postgres), all special UTF-8 characters were not displaying correctly.
After some googling and some testing I found this solution (that is, make sure Rails and MySQL is all UTF-8), but it wasn’t enough to properly import the old data. After more googling, this worked for me:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysqldump --user=username --password --default-character-set=latin1 --skip-set-charset dbname > dump.sql | |
sed 's/latin1/utf8/g' dump.sql > dump_utf.sql | |
mysql --user=username --password --execute="DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;" | |
mysql --user=username --password --default-character-set=utf8 dbname < dump_utf.sql |