Hi guys,

I have a rails application, in which I am using ‘delayed_job_active_record
<https://github.com/collectiveidea/delayed_job>’ gem for running background
jobs. While using the method ‘.delay’ with an object, I am getting the
following mysql error:

"*‘Incorrect string value: '\xE2\x9C\x93"\x0A ...' for column 'handler' at
row 1"*
  I already searched for the above error and found that its because of the
difference in encoding in mysql and rails. The solution suggested by many
programmers is to alter the encoding in mysql database to utf8. But I also
read <https://mathiasbynens.be/notes/mysql-utf8mb4> that MySQL’s utf8
charset only partially implements proper UTF-8 encoding. It can only store
UTF-8-encoded symbols that consist of one to three bytes; encoded symbols
that take up four bytes aren’t supported. Which might cause trouble in some
other cases. Also, when I tried to insert the value directly in mysql, it
worked like a charm. Suggesting that the issue might lie elsewhere. So, can
anyone please suggest the right method to rectify this problem?

Any help would be greatly appreciated.

Thanks,

Kriti

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ad73d3be-5cb6-47c3-af6b-9dd1935939f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Hassan Schroeder at Jan 5, 2015 at 4:55 pm

    On Mon, Jan 5, 2015 at 2:44 AM, Kriti Aggarwal wrote:

    I am getting the following mysql error:
    "‘Incorrect string value: '\xE2\x9C\x93"\x0A ...' for column 'handler' at
    row 1"
    I already searched for the above error and found that its because of the
    difference in encoding in mysql and rails.
    So, what encodings/collations *are* you using? And what version of
    MySQL? What versions of Ruby and Rails?

    --
    Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
    http://about.me/hassanschroeder
    twitter: @hassan

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yAOa%2Bip%2BOLo06oJWte8QedqFPLfw-UwnT0cw7RWS6%2BJRA%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kriti Aggarwal at Jan 5, 2015 at 6:00 pm
    Following are the encodings/collations and versions that I am using:
    Rails : utf8, 4.0
    Mysql: latin_general_ci, 14.14 Distrib 5.5.40
    On Monday, January 5, 2015 10:25:32 PM UTC+5:30, Hassan Schroeder wrote:

    On Mon, Jan 5, 2015 at 2:44 AM, Kriti Aggarwal <krit...@gmail.com
    <javascript:>> wrote:
    I am getting the following mysql error:
    "‘Incorrect string value: '\xE2\x9C\x93"\x0A ...' for column 'handler'
    at
    row 1"
    I already searched for the above error and found that its because of the
    difference in encoding in mysql and rails.
    So, what encodings/collations *are* you using? And what version of
    MySQL? What versions of Ruby and Rails?

    --
    Hassan Schroeder ------------------------ hassan.s...@gmail.com
    <javascript:>
    http://about.me/hassanschroeder
    twitter: @hassan
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8bf34842-1fc4-4527-b940-a1b8b7e0b8a8%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Hassan Schroeder at Jan 5, 2015 at 6:13 pm

    On Mon, Jan 5, 2015 at 10:00 AM, Kriti Aggarwal wrote:
    Following are the encodings/collations and versions that I am using:
    Rails : utf8, 4.0
    Mysql: latin_general_ci, 14.14 Distrib 5.5.40
    Well, it should be pretty obvious you have a mismatch there, which is
    a problem. But there's not just one encoding-related variable. Example:

    mysql> show variables like '%char%';
    +--------------------------+--------------------------------------------------------+
    Variable_name | Value
    +--------------------------+--------------------------------------------------------+
    character_set_client | utf8

    character_set_connection | utf8

    character_set_database | utf8

    character_set_filesystem | binary

    character_set_results | utf8

    character_set_server | utf8

    character_set_system | utf8

    character_sets_dir |
    /usr/local/mysql-5.6.13-osx10.7-x86_64/share/charsets/ |
    +--------------------------+--------------------------------------------------------+
    8 rows in set (0.00 sec)

    mysql> show variables like '%coll%';
    +----------------------+-----------------+
    Variable_name | Value |
    +----------------------+-----------------+
    collation_connection | utf8_general_ci |
    collation_database | utf8_general_ci |
    collation_server | utf8_general_ci |
    +----------------------+-----------------+
    3 rows in set (0.01 sec)

    You want, at the least, all of those consistent. If you need the 4-byte
    character capability, then set them appropriately.

    Note: you'll need to manually alter (or drop and recreate) existing
    databases/tables afterwards.

    HTH,
    --
    Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
    http://about.me/hassanschroeder
    twitter: @hassan

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yAo24dapsXhNqWgAtvpKx1KXZeBUmL5sgm377uBbrnKzQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kriti Aggarwal at Jan 6, 2015 at 5:36 am
    Thanks for the insight, but I think the issue is at the rails level. Since
    when I tried inserting the same values in the mysql db directly, it worked
    without any errors. It might be because the character that I am trying to
    insert is not UTF8. But rails is enforcing that encoding. What would be the
    encoding change required to be done at rails level?

    Also, I have a system where I would need to scale things later. So, I would
    have to change the encoding of a particular table every time I have to
    create a new instance. Is there any way to deal with that?
    On Monday, January 5, 2015 11:43:31 PM UTC+5:30, Hassan Schroeder wrote:

    On Mon, Jan 5, 2015 at 10:00 AM, Kriti Aggarwal <krit...@gmail.com
    <javascript:>> wrote:
    Following are the encodings/collations and versions that I am using:
    Rails : utf8, 4.0
    Mysql: latin_general_ci, 14.14 Distrib 5.5.40
    Well, it should be pretty obvious you have a mismatch there, which is
    a problem. But there's not just one encoding-related variable. Example:

    mysql> show variables like '%char%';
    +--------------------------+--------------------------------------------------------+
    Variable_name | Value
    +--------------------------+--------------------------------------------------------+
    character_set_client | utf8

    character_set_connection | utf8

    character_set_database | utf8

    character_set_filesystem | binary

    character_set_results | utf8

    character_set_server | utf8

    character_set_system | utf8

    character_sets_dir |
    /usr/local/mysql-5.6.13-osx10.7-x86_64/share/charsets/ |
    +--------------------------+--------------------------------------------------------+

    8 rows in set (0.00 sec)

    mysql> show variables like '%coll%';
    +----------------------+-----------------+
    Variable_name | Value |
    +----------------------+-----------------+
    collation_connection | utf8_general_ci |
    collation_database | utf8_general_ci |
    collation_server | utf8_general_ci |
    +----------------------+-----------------+
    3 rows in set (0.01 sec)

    You want, at the least, all of those consistent. If you need the 4-byte
    character capability, then set them appropriately.

    Note: you'll need to manually alter (or drop and recreate) existing
    databases/tables afterwards.

    HTH,
    --
    Hassan Schroeder ------------------------ hassan.s...@gmail.com
    <javascript:>
    http://about.me/hassanschroeder
    twitter: @hassan
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1646bb47-2dc1-4306-8112-c663e008b0e8%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Hassan Schroeder at Jan 6, 2015 at 6:26 am

    On Mon, Jan 5, 2015 at 9:36 PM, Kriti Aggarwal wrote:
    Thanks for the insight, but I think the issue is at the rails level.
    Have you confirmed that all the character set/collation settings I
    mentioned are consistent? Including the encoding specified in
    config/database.yml?

    That's basic configuration. If you don't fix it, well, good luck.
    Also, I have a system where I would need to scale things later. So, I would
    have to change the encoding of a particular table every time I have to
    create a new instance. Is there any way to deal with that?
    Sorry, I have no idea what the above paragraph means. Can you
    clarify "create a new instance"?

    --
    Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
    http://about.me/hassanschroeder
    twitter: @hassan

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yAbDFxJv1Dw6VXokbjo2zzP%2B%3DtQaLAo0JyLuDsPYg4gxg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 5, '15 at 10:49a
activeJan 6, '15 at 6:26a
posts6
users2
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase