MySQL创建数据库并⽀持中⽂字符的操作⽅法
我们⾸先看⼀下MySQL官⽅⽂档:
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
[create_option] ...
create_option: [DEFAULT] {
CHARACTER SET [=] charset_name
| COLLATE [=] collation_name
}
通过查看mysql服务器的变量我们知道mysql默认创建数据库开启的字符集是latinl:
现在我们需要给创建的数据库db2指定⽀持中⽂的字符集utf8,下⾯是⼀⾏的内容哦!
CREATE DATABASE db2 IF NOT EXISTS db2
DEFAULT CHARACTER SET utf8
mysql面试题 知乎COLLATE utf_general_ci;
上⾯我们就完成⽀持插⼊中⽂数据的数据库的创建,现在我们来思考⼀个问题,⽀持中⽂的字符集就只有utf8,还有哪些呢?它们之间的区别是什么?
我们先来看⼀下mysql 5.7.x ⽀持的字符集以及字符规则:
mysql> SELECT version();
+-----------+
| version() |
+-----------+
| 5.7.32 |
+-----------+
1 row in set (0.00 sec)
mysql> SHOW CHARACTER SET;
+----------+---------------------------------+---------------------+--------+
| Charset | Description  | Default collation | Maxlen |
+----------+---------------------------------+---------------------+--------+
| big5 | Big5 Traditional Chinese | big5_chinese_ci | 2 |
| dec8 | DEC West European | dec8_swedish_ci | 1 |
| cp850 | DOS West European | cp850_general_ci | 1 |
| hp8 | HP West European | hp8_english_ci | 1 |sqlyog怎么查询数据
| koi8r | KOI8-R Relcom Russian | koi8r_general_ci | 1 |
| latin1 | cp1252 West European | latin1_swedish_ci | 1 |
| latin2 | ISO 8859-2 Central European | latin2_general_ci | 1 |
| swe7 | 7bit Swedish  | swe7_swedish_ci | 1 |
| ascii | US ASCII  | ascii_general_ci | 1 |
| ujis | EUC-JP Japanese  | ujis_japanese_ci | 3 |
| sjis | Shift-JIS Japanese | sjis_japanese_ci | 2 |
| hebrew | ISO 8859-8 Hebrew | hebrew_general_ci | 1 |
| tis620 | TIS620 Thai  | tis620_thai_ci | 1 |
| euckr | EUC-KR Korean  | euckr_korean_ci | 2 |
| koi8u | KOI8-U Ukrainian | koi8u_general_ci | 1 |
| gb2312 | GB2312 Simplified Chinese | gb2312_chinese_ci | 2 |
| greek | ISO 8859-7 Greek | greek_general_ci | 1 |
| cp1250 | Windows Central European | cp1250_general_ci | 1 |
| gbk | GBK Simplified Chinese | gbk_chinese_ci | 2 |
| latin5 | ISO 8859-9 Turkish | latin5_turkish_ci | 1 |
公式当成数组处理什么意思
| armscii8 | ARMSCII-8 Armenian | armscii8_general_ci | 1 |
| utf8 | UTF-8 Unicode  | utf8_general_ci | 3 |
| ucs2 | UCS-2 Unicode  | ucs2_general_ci | 2 |
| cp866 | DOS Russian  | cp866_general_ci | 1 |
| keybcs2 | DOS Kamenicky Czech-Slovak | keybcs2_general_ci | 1 |
| macce | Mac Central European | macce_general_ci | 1 |
| macroman | Mac West European | macroman_general_ci | 1 |
| cp852 | DOS Central European | cp852_general_ci | 1 |
| latin7 | ISO 8859-13 Baltic | latin7_general_ci | 1 |
| utf8mb4 | UTF-8 Unicode  | utf8mb4_general_ci | 4 |
| cp1251 | Windows Cyrillic | cp1251_general_ci | 1 |
| utf16 | UTF-16 Unicode  | utf16_general_ci | 4 |
| utf16le | UTF-16LE Unicode | utf16le_general_ci | 4 |
| cp1256 | Windows Arabic  | cp1256_general_ci | 1 |
| cp1257 | Windows Baltic  | cp1257_general_ci | 1 |
源代码英语在线观看| utf32 | UTF-32 Unicode  | utf32_general_ci | 4 |
| binary | Binary pseudo charset | binary | 1 |
| geostd8 | GEOSTD8 Georgian | geostd8_general_ci | 1 |前端用ajax与mysql交互
| cp932 | SJIS for Windows Japanese | cp932_japanese_ci | 2 |
| eucjpms | UJIS for Windows Japanese | eucjpms_japanese_ci | 3 |
| gb18030 | China National Standard GB18030 | gb18030_chinese_ci | 4 |
+----------+---------------------------------+---------------------+--------+
41 rows in set (0.00 sec)
前序线索化二叉树算法gb2312、gbk、gb18030、utf8、utf8mb4 这四个字符集都是⽀持中⽂。
关于gb2312、gbk、gb18030的介绍参考知乎这篇:
关于utf8、utf8mb4的介绍参考这篇:
到此这篇关于MySQL创建数据库并⽀持中⽂字符的操作⽅法的⽂章就介绍到这了,更多相关MySQL⽀持中⽂字符内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。