tags:

views:

460

answers:

3

When create table, I have setted charset = utf8.

I create 1 store procedure to insert data to database.

  1. When insert data UTF8 to Database on Window, it works OK.(Display data correctly)
  2. But it doesnot work in Linux.(Display data not correctly)

The strange thing is insert UTF8 work fine in window, but when i deploy MySQL in linux, when insert data to database it insert wrong UTF8 value.

Thanks for help

Edit: Update more detail follow comment of @Col. Shrapnel

+2  A: 

most probably you didn't specify client character set by issuing SET NAMES UTF8 query

but there can be other problems - your database or a web page may be not in the utf-8

Col. Shrapnel
I try to insert into Database with original SQLcommand. For example:insert into tbData values('UTF8-Data','');It does NOT insert correct UTF8 value to database. How can i fix this problem?
nguyendat
@nguyendat you must execute `SET NAMES UTF8` query **before** any other query. just make it below connect statement
Col. Shrapnel
+3  A: 

You should start mysql console with --default-character-set=utf8:

mysql --default-character-set=utf8 -uyour_user -p
newtover
Thanks. You saved my hours.Not exactly a linux problem in my case. I was running an sql script which contained UTF-8 data in INSERT statements. I was using mysql.exe on the command line. mysql.exe -uname -ppassword < script.sql
Satish Motwani
@satishmotwani: you are welcome
newtover
A: 

I just found a solution for my problem: Edit file my.cnf under /etc/my.cnf as below:

[mysqld]
default-character-set=utf8
default-collation=utf8_general_ci
character-set-server=utf8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'

[client]
default-character-set=utf8

But i still confuse why this bug occur in Linux, not in Window.

nguyendat
This is not a bug, this is a configuration issue.
newtover