views:

238

answers:

2

On SQLITE this way fine. I switch to mysql and instead of クイン i get ???. The column is TEXT or sometimes VARCHAR(255) (i believe its VARCHAR(255) in this case).

How do i have mysql save the characters properly?

+1  A: 

Table/column character sets need to be set to a version that supports multibyte like UTF8.

You may be able to tell the current table character set by doing a

mysql> SHOW CREATE TABLE tbl_Name;

It may not show you anything in which case it's using the default defined in you my.cnf

To change a character set on a table run:

mysql> ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

I don't recommend this if you have a lot of data or can't remove the data and start fresh. The transition needs to remove the bad data first.

I read through this post and it seems in depth and from what I can remember of my own battles with this very accurate. http://www.oreillynet.com/onlamp/blog/2006/01/turning_mysql_data_in_latin1_t.html

Also, to create new tables as UTF-8 append *CHARACTER SET utf8 COLLATE utf8_general_ci* to the end of your CREATE TABLE statements

Matt S
converting the character set doesn't convert the data. Use the command with care, only as part of an overall migration strategy.
David M
As pointed out directly below the command. It was to convert the table for future storage not to convert the data currently in the table.
Matt S
Its a prototype so i can start with fresh data. AFAIK .NET uses 16bit chars (i dont know if its UTF encoded/supports>16bits character). Would setting UTF-8 force me to pass the data as utf8? I tried writing `CHARACTER SET utf8 COLLATE utf8_general_ci` after TEXT and varchar(255) yet it still gives me ?? instead.
acidzombie24
SHOW CREATE TABLE tbl_Name; outputs ` name varchar(255) character set utf8 NOT NULL,`
acidzombie24
Matt S
+1  A: 

Verify that you have specified "charset=utf8" in your connection string. For example

connectionString="Server=myServerHost;charset=UTF8;Database=myDatabase;Uid=root;Pwd=password;"

As noted in Character Sets and Collations in General MySQL can do:

  • Store strings using a variety of character sets
  • Compare strings using a variety of collations
  • Mix strings with different character sets or collations in the same server, the same database, or even the same table
  • Allow specification of character set and collation at any level
volody