Report this

What is the reason for this report?

rails with mysql utf8 error

Posted on July 5, 2014

Hi all

I am trying to deploy a ruby on rails application with mysql2 on this droplet, when I post some data into the mysql db, it shows the following error message, the database seems can’t post utf8 data, anyone know what’s wrong??

INFO -- : Started POST "/groups" for 61.64.150.230 at 2014-07-04 22:37:17 +0800 
I, [2014-07-04T22:37:17.803169 #28481] INFO -- : Processing by GroupsController#create as HTML 
I, [2014-07-04T22:37:17.803263 #28481] INFO -- : Parameters: {"utf8"=>"✓", "authenticity_token"=>"MaAEh3zwRVZcsqZn2OoUMtijmrgSRj/i5lYgiJj8ioM=", "group"=>{"title"=>"中文", "descr 
iption"=>""}, "commit"=>"Create Group"} 
E, [2014-07-04T22:37:17.808026 #28481] ERROR -- : Mysql2::Error: Incorrect string value: '\xE4\xB8\xAD\xE6\x96\x87' for column 'title' at row 1: INSERT INTO `groups` (`created_at`, 
`description`, `title`, `updated_at`, `user_id`) VALUES ('2014-07-04 14:37:17', '', '中文', '2014-07-04 14:37:17', 1) 
I, [2014-07-04T22:37:17.808531 #28481] INFO -- : Completed 500 Internal Server Error in 5ms 
F, [2014-07-04T22:37:17.820777 #28481] FATAL -- :


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

CHECK MYSQL CONF SERVER. USING PHPMYADMIN OR WEBMIN. ETC.

It seems like you are having issue with the character encoding. On the server, try changing your MySql configuration with:

ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_general_ci;

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.