# csv/Rails 3/ruby 1.9.2p0/mysql encoding problem

**URL:** <https://www.ruby-forum.com/t/csv-rails-3-ruby-1-9-2p0-mysql-encoding-problem/195054>\
**Category:** Rails\
**Created:** [September 15, 2010, 11:01pm UTC](https://www.ruby-forum.com/t/csv-rails-3-ruby-1-9-2p0-mysql-encoding-problem/195054 "2010-09-15T23:01:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@paul](https://www.ruby-forum.com/u/paul)\
**Post date:** [September 15, 2010, 11:01pm UTC](https://www.ruby-forum.com/t/csv-rails-3-ruby-1-9-2p0-mysql-encoding-problem/195054/1 "2010-09-15T23:01:28Z")

</div>

I’m having an encoding problem, even though I’m attempting to have all  
my data always be in utf-8. Here’s the path the data takes:

I have a CSV file that I believe is in utf-8, because I’m looking at  
it in a hex editor. One of the words is:

64 65 62 74 6F 72 E2 80 99 73

which translates to:

debtor‚Äôs [that is, it contains a smart apostrophe]

Now, I’m reading that string in using:

require ‘csv’  
CSV.foreach(fname, :encoding =\> ‘u’) do |row|

Then I’m just storing that string using the standard ActiveRecord  
method.

In mysql, when I do “show table status;”, I get “utf8\_unicode\_ci” as  
the encoding for all the tables.

When I try to display that data in a browser, however, I get a 500  
error with the message:

“incompatible character encodings: ASCII-8BIT and UTF-8”

In the header of my page, I see:

Content-Type text/html; charset=UTF-8

I don’t know where else to look.

How can I tell what exactly is stored in the database? If I go into  
mysql and query, I get a single question mark in place of the  
character, but I don’t know if that is caused by a translation after  
the fact. In other words, I’ve ssh’d to the centos machine, started  
mysql and did a select. I get:

debtor?s

(Note: the page works correctly on my OS X development machine, using  
Ruby 1.8.7, so that is making debugging more challenging.)

---

<div class="post-metadata">

**Author:** ![paul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@paul](https://www.ruby-forum.com/u/paul)\
**Post date:** [September 15, 2010, 11:33pm UTC](https://www.ruby-forum.com/t/csv-rails-3-ruby-1-9-2p0-mysql-encoding-problem/195054/2 "2010-09-15T23:33:05Z")

</div>

I have a little more info: I did a mysqldump and looked at that in my  
text editor and I see that the word appears to be encoded correctly in  
mysql, at least after being run through mysqldump.

It still looks like: 64 65 62 74 6F 72 E2 80 99 73, i.e. “debtor‚Äôs”
