Question

My problem is my API server can not store a character which is possible to display on iOS client. The character is 1F49D (http://shapecatcher.com/unicode/info/128157).

Server side:

  • ruby 1.9.3-p327
  • activerecord 3.2 with mysql2
  • MySQL server: 5.5.28

FYI:

  1. previously our iOS client used parse.com as persistence service. Now, we move to our owned API server (implemented in ruby).
  2. When I try with irb. Ruby 1.9 is possible to read and understand this character.
  3. Here is the text containing character. https://gist.github.com/jacobdam/6220339/raw/1562815fe37df04293d3cee7d216e920415de715/gistfile1.txt
  4. I changed the schema, table, column collation to utf8 and utf16. But it does not work.

Anyone can give me an advice how to persist/retreive this text to/from mysql?

Was it helpful?

Solution

Prerequisite: MySQL >= 5.5.3

Character set named utf8 (or utf8mb3) uses a maximum of three bytes per character and contains only BMP characters. In order to have a maximum of four bytes per character, you need to:

  1. switch charset/collation of all your tables/columns to utf8mb4
  2. edit your config/database.yml to change the encoding: utf8 lines to encoding: utf8mb4

(and a recent mysql2 gem?)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top