NguyenDat
NguyenDat

Reputation: 4159

Can not insert UTF8 to Database MySQL in Linux

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

Upvotes: 1

Views: 7835

Answers (3)

NguyenDat
NguyenDat

Reputation: 4159

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.

Upvotes: 3

newtover
newtover

Reputation: 32094

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

mysql --default-character-set=utf8 -uyour_user -p

Upvotes: 11

Your Common Sense
Your Common Sense

Reputation: 157915

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

Upvotes: 3

Related Questions