12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
mysql默认字符集是latin1,而该字符集是不支持中文的,所以导致当插入的数据含有中文时,会出现乱码或者无法插入到数据库中;在mysql实践中,建议使用utf8mb4来作为默认的字符集。mys
以下为本文的正文内容,请查阅,本站为公益性网站,复制本文以及下载DOC文档全部免费。
mysql默认字符集是latin1,而该字符集是不支持中文的,所以导致当插入的数据含有中文时,会出现乱码或者无法插入到数据库中;在mysql实践中,建议使用utf8mb4来作为默认的字符集。
mysql默认字符集是什么?
mysql安装时默认设置的字符集是latin1,而它是不支持中文,所以导致当插入的数据含有中文时,会出现乱码或者无法插入到数据库中。
MySQL 默认字符集建议使用utf8mb4 ,而非 utf8
MySQL 中 utf8 最多使用3个字节(bytes)来存放一个字符,因此和utf8mb3是一个意思。
而 utf8mb4 是 utf8mb3 的超集,最多允许使用4个字符来存放字符。
在实践中,建议使用 utf8mb4 来作为默认的字符集,如果使用 utf8 ,可能有很多生僻字,比如"?","?","?"等无法输入到 MySQL 数据库(会类似如下报错: ERROR 1366 (HY000): Incorrect string value: '\xF0\xA0\x86\xB7' for column 'name' at row 1)
查看MySQL支持的字符集:
mysql>showcharacterset;+----------+---------------------------------+---------------------+--------+|Charset|Description|Defaultcollation|Maxlen|+----------+---------------------------------+---------------------+--------+|big5|Big5TraditionalChinese|big5_chinese_ci|2||dec8|DECWestEuropean|dec8_swedish_ci|1||cp850|DOSWestEuropean|cp850_general_ci|1||hp8|HPWestEuropean|hp8_english_ci|1||koi8r|KOI8-RRelcomRussian|koi8r_general_ci|1||latin1|cp1252WestEuropean|latin1_swedish_ci|1||latin2|ISO8859-2CentralEuropean|latin2_general_ci|1||swe7|7bitSwedish|swe7_swedish_ci|1||ascii|USASCII|ascii_general_ci|1||ujis|EUC-JPJapanese|ujis_japanese_ci|3||sjis|Shift-JISJapanese|sjis_japanese_ci|2||hebrew|ISO8859-8Hebrew|hebrew_general_ci|1||tis620|TIS620Thai|tis620_thai_ci|1||euckr|EUC-KRKorean|euckr_korean_ci|2||koi8u|KOI8-UUkrainian|koi8u_general_ci|1||gb2312|GB2312SimplifiedChinese|gb2312_chinese_ci|2||greek|ISO8859-7Greek|greek_general_ci|1||cp1250|WindowsCentralEuropean|cp1250_general_ci|1||gbk|GBKSimplifiedChinese|gbk_chinese_ci|2||latin5|ISO8859-9Turkish|latin5_turkish_ci|1||armscii8|ARMSCII-8Armenian|armscii8_general_ci|1||utf8|UTF-8Unicode|utf8_general_ci|3||ucs2|UCS-2Unicode|ucs2_general_ci|2||cp866|DOSRussian|cp866_general_ci|1||keybcs2|DOSKamenickyCzech-Slovak|keybcs2_general_ci|1||macce|MacCentralEuropean|macce_general_ci|1||macroman|MacWestEuropean|macroman_general_ci|1||cp852|DOSCentralEuropean|cp852_general_ci|1||latin7|ISO8859-13Baltic|latin7_general_ci|1||utf8mb4|UTF-8Unicode|utf8mb4_general_ci|4||cp1251|WindowsCyrillic|cp1251_general_ci|1||utf16|UTF-16Unicode|utf16_general_ci|4||utf16le|UTF-16LEUnicode|utf16le_general_ci|4||cp1256|WindowsArabic|cp1256_general_ci|1||cp1257|WindowsBaltic|cp1257_general_ci|1||utf32|UTF-32Unicode|utf32_general_ci|4||binary|Binarypseudocharset|binary|1||geostd8|GEOSTD8Georgian|geostd8_general_ci|1||cp932|SJISforWindowsJapanese|cp932_japanese_ci|2||eucjpms|UJISforWindowsJapanese|eucjpms_japanese_ci|3||gb18030|ChinaNationalStandardGB18030|gb18030_chinese_ci|4|+----------+---------------------------------+---------------------+--------+41rowsinset(0.00sec)
要设置默认的字符集为 utf8mb4 ,需要在配置文件中设置以下变量:
[mysqld]character-set-server=utf8mb4[mysql]default-character-set=utf8mb4
11-19
11-19
11-19
11-19
11-19
11-19
11-19
11-19
11-19
11-19
11-19
11-19
11-19
11-19
11-19
11-19