2
votes

I am inserting some non-ascii(specifically asian characters into mysql table column with charset utf8, but after insertion, if I retrieve it again, it shows up as ????. I checked the db, table and column charset, they are all utf8. what's wrong?

CREATE TABLE `test_utf` (
  `test_id` bigint(20) NOT NULL auto_increment,
  `raw_text` longtext,
  PRIMARY KEY  (`test_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;



insert into test_utf (raw_text) values('黄剑');
1
Where are you displaying them? In a terminal window? Is your terminal set to interpret bytes as UTF-8-encoded characters?Ray Toal

1 Answers

3
votes

Problem solved!

I need to add characterEncoding=UTF-8 to whatever mysql client I'm using,

for example, when I use jdbc I need to specify "jdbc:mysql://localhost/dbname?characterEncoding=UTF-8" in connection url.