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.
MySQL supports multiple Unicode character sets: utf8mb4 : A UTF-8 encoding of the Unicode character set using one to four bytes per character. utf8mb3 : A UTF-8 encoding of the Unicode character set using one to three bytes per character. utf8 : An alias for utf8mb3 .
Varchar uses Windows-1252 character encoding, which is for all practical purposes standard ASCII. As others have noted, nvarchar allows the storage of unicode characters.
To change the character set encoding to UTF-8 for the database itself, type the following command at the mysql> prompt. Replace dbname with the database name: Copy ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci; To exit the mysql program, type \q at the mysql> prompt.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With