开发者

How to store unicode in MySQL?

开发者 https://www.devze.com 2023-01-08 14:01 出处:网络
How do I store Unicode in free edition of MySQL? There doesn\'t seem to be nvarchar type as in 开发者_开发知识库SQL Server. Is Unicode not supported in MySQL? I tried using text but that too is not w

How do I store Unicode in free edition of MySQL?

There doesn't seem to be nvarchar type as in 开发者_开发知识库SQL Server. Is Unicode not supported in MySQL? I tried using text but that too is not working.


You need to choose a utf8_* character set for your table. Text and memo fields will then automatically be stored in UTF-8. Support for UTF-16 is coming in mySQL 6.


The character set for a given string column (CHAR, VARCHAR or *TEXT) is determined by its character set and/or collation. This is a quite intense topic so it's best to read the documentation I linked. For example:

CREATE TABLE t1
(
    col1 CHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci
)

will create a table t1 with a col1 that stores its content in UTF-8 encoding.


Have you tried setting names after connection? What was the outcome of tryng to store unicode characters? Connect to mysql server and type this:

SET NAMES UTF8;

This should turn on "support" for utf8. Then try storing utf data.


  • MySQL supports UTF-8.
  • Use varchar and set encoding for the column (it's quite easy in phpMyAdmin)

http://www.oreillynet.com/onlamp/blog/2006/01/turning_mysql_data_in_latin1_t.html - I think this could help you


Use this Query

alter table `DBNAME`.`TblName`  Engine=InnoDB checksum=1 comment='' delay_key_write=1 row_format=dynamic charset=utf8 collate=utf8_unicode_ci 


I follow my own style of coding, so please take that into account when following my lead.

First I created the MySql database.

after creating database, in mysql command prompt, give the command:

SET NAMES = UTF8;

table and columns to store unicode are to be set with collation property as utf8-utf_general_ci. Each and every column which meant to store unicode, is to be selected and set collation property to utf8-utf_general_ci.

Now in C#.

my connection string is set as usual but with addition of a single attribute like this:

constring = @"SERVER=localhost;" + @"PORT=3306;" + @"DATABASE=gayakidb;" + @"UID=root;" + @"PASSWORD=mysql;" + @"charset=utf8;";

Next, installed unicode font in the 'Display language setting' of your system OS. Or, you can copy and paste the font file (true type file) in the Fonts folder of Operating System.

Then I set the font property of the textbox object or any other tool object in property page.

More over, if you need to type in unicode font using your keyboard, you need to install the unicode language for keyboard layout. That could be done using the option for regional language settings of your Operating System.

Done. with these settings, i coded module for saving data and while running the ocde, it successfully done the work.

0

精彩评论

暂无评论...
验证码 换一张
取 消