字符集,utf8mb4,如果数据库字符集使用utf8mb4,校对规则为utf8mb4_unicode_ci;
mysql创建数据库可以用以下语句:
CREATE DATABASE IF NOT EXISTS test_db
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_chinese_ci;
指定其默认字符集为 utf8,默认校对规则为 utf8_chinese_ci(简体中文,不区分大小写)
但如果要使用字符集utf8mb4,校对规则为 utf8_chinese_ci时就会报错
mysql> CREATE DATABASE IF NOT EXISTS tyfncms default charset utf8mb4 COLLATE utf8_general_ci;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 43
Current database: test
ERROR 1253 (42000): COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'utf8mb4'
如果要使用utf8mb4,校对规则应设为utf8mb4_unicode_ci;
CREATE DATABASE IF NOT EXISTS test_db
default charset utf8mb4
COLLATE utf8mb4_unicode_ci;
如下:
mysql> CREATE DATABASE IF NOT EXISTS test_db default charset utf8mb4 COLLATE utf8mb4_unicode_ci;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test_db |
+--------------------+
8 rows in set (0.00 sec)
mysql> SHOW CREATE DATABASE test_db;
+----------+--------------------------------------+
| Database | Create Database |
+----------+--------------------------------------+
| test_db | CREATE DATABASE `test_db` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */ |
+----------+--------------------------------------+
1 row in set (0.00 sec)
mysql>
Tag: 字符集 utf8mb4