Cannot create NVARCHAR column in MariaDb/Mysql

2019-03-01 03:58发布

问题:

I'm using MariaDb server (Ver 15.1 Distrib 10.2.7-MariaDB). When I execute

CREATE TABLE `my_table` (
   `id` INT NOT NULL,
   `name` NVARCHAR(64) NULL,
   PRIMARY KEY (`id`)
);

Describe output:

MariaDB [db]> describe my_table;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| name  | varchar(64) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

Why there is no error, and "name" column datatype is varchar (not nvarchar)?

db schema details:

Default collation: utf8_general_ci
Default characterset: utf8

回答1:

NVARCHAR is a synonym for VARCHAR in MySQL/MariaDB. But you need to add the CHARACTER SET utf8mb4 to be sure that you get full UTF-8 support.

What you show as the default for that database is only the subset, called 'utf8'. It will not handle Emoji or some of Chinese.