# Problem with adding a new record into MySQL DB

**URL:** <https://www.ruby-forum.com/t/problem-with-adding-a-new-record-into-mysql-db/98050>\
**Category:** Ruby\
**Created:** [July 12, 2006, 6:53am UTC](https://www.ruby-forum.com/t/problem-with-adding-a-new-record-into-mysql-db/98050 "2006-07-12T06:53:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 12, 2006, 6:53am UTC](https://www.ruby-forum.com/t/problem-with-adding-a-new-record-into-mysql-db/98050/1 "2006-07-12T06:53:28Z")

</div>

MySQL DB’s character-set is UTF8 and RoR(Ruby on Rails)'s database.yml  
has a line ‘encoding: utf8’.  
If I add a new record using RoR’s new action via Web Browser, Korean is  
stored without problem.  
If I set fiels explicitly like 'MyActionRecord[‘fieldname’] = ‘’, and invoke save method… yes, it works, but Korean  
is not saved correctly. English was okay with same code.

How can I convert Korean letters to UTF8 characters? I did many tries  
and finally I’m here.

irb(main):001:0\> “í??ê¸?” \<-- I can’t sure you guys can see this  
letter. They are just two Korean letters.  
=\> “\307\321\261\333” \<— What the hell…T^T  
irb(main):002:0\> “aaa” \<— English, of course.  
=\> “aaa” \<— No problem. - -

Please help…

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 12, 2006, 7:39am UTC](https://www.ruby-forum.com/t/problem-with-adding-a-new-record-into-mysql-db/98050/2 "2006-07-12T07:39:43Z")

</div>

On 7/12/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> MySQL DB’s character-set is UTF8 and RoR(Ruby on Rails)'s database.yml  
> has a line ‘encoding: utf8’.  
> If I add a new record using RoR’s new action via Web Browser, Korean is  
> stored without problem.  
> If I set fiels explicitly like 'MyActionRecord[‘fieldname’] = ‘’, and invoke save method… yes, it works, but Korean  
> is not saved correctly. English was okay with same code.

Firstly you want the rails list at  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Secondly chances are you’re not sending your web pages with the  
content-type set correctly. Use something like LiveHTTPHeaders for  
Firefox (don’t have a URL I’m sorry) and see if you get a line like  
this:  
Content-Type: text/html; charset=utf8

you’re sending UTF8 encoded pages, if not then you need to send it.  
I’m not sure on how to do this in Rails, see the Rails list.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 15, 2006, 6:02am UTC](https://www.ruby-forum.com/t/problem-with-adding-a-new-record-into-mysql-db/98050/3 "2006-07-15T06:02:42Z")

</div>

On Jul 12, 2006, at 12:50 AM, removed\_email\_address@domain.invalid wrote:

> and finally I’m here.
> 
> irb(main):001:0\> “í??ê¸?” \<-- I can’t sure you guys can see this  
> letter. They are just two Korean letters.  
> =\> “\307\321\261\333” \<— What the hell…T^T  
> irb(main):002:0\> “aaa” \<— English, of course.  
> =\> “aaa” \<— No problem. - -
> 
> Please help…

I can see it. 🙂  
Secondly, the output from irb is the #inspect string. Try doing  
puts “í??ê¸?”

and see if that gives you what you expect. (Works good for me)
