MySQL not storing foreign characters correctly
Using SQLite, this works fine. However, when I switch to MySQL, instead of クイン
i get ???
. The column is TEXT or sometimes VARCHAR(255) (I believe its VARCHAR(255) in开发者_如何学C this case).
How do I get MySQL to properly save these characters?
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
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
精彩评论