45

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.

shA.t
  • 16,580
  • 5
  • 54
  • 111
TCM
  • 16,780
  • 43
  • 156
  • 254

6 Answers6

33

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.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • 7
    Update: UTF-16 & Emoji (utf8mb4) support is introduced since version 5.5: http://dev.mysql.com/doc/refman/5.5/en/charset-unicode.html – Raptor Dec 29 '14 at 04:24
  • 2
    It's worth noting that depending on how you retrieve the data from the database it might also be necessary to explicitly let the connection use UTF-8 as well. – hugovdberg Jan 06 '18 at 12:14
27

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.

Stefan Gehrig
  • 82,642
  • 24
  • 155
  • 189
2

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.

Kzqai
  • 22,588
  • 25
  • 105
  • 137
2

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.

Eimantas
  • 48,927
  • 17
  • 132
  • 168
2
  • 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

MartyIX
  • 27,828
  • 29
  • 136
  • 207
2

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