最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

使MySQL能夠存儲emoji表情字符的設(shè)置教程_MySQL

來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-09 20:15:44
文檔

使MySQL能夠存儲emoji表情字符的設(shè)置教程_MySQL

使MySQL能夠存儲emoji表情字符的設(shè)置教程_MySQL:MySQL 需要支持 emoji 表情符號版本需要大于5.5.3,且字符集需要設(shè)置為utf8mb4 字符集。utf8mb4和utf8到底有什么區(qū)別呢?原來以往的mysql的utf8一個字符最多3字節(jié),而utf8mb4則擴(kuò)展到一個字符最多能有4字節(jié),所以能支持更多的字符集。將Mysql的編碼從u
推薦度:
導(dǎo)讀使MySQL能夠存儲emoji表情字符的設(shè)置教程_MySQL:MySQL 需要支持 emoji 表情符號版本需要大于5.5.3,且字符集需要設(shè)置為utf8mb4 字符集。utf8mb4和utf8到底有什么區(qū)別呢?原來以往的mysql的utf8一個字符最多3字節(jié),而utf8mb4則擴(kuò)展到一個字符最多能有4字節(jié),所以能支持更多的字符集。將Mysql的編碼從u

MySQL 需要支持 emoji 表情符號版本需要大于5.5.3,且字符集需要設(shè)置為utf8mb4 字符集。


utf8mb4和utf8到底有什么區(qū)別呢?原來以往的mysql的utf8一個字符最多3字節(jié),而utf8mb4則擴(kuò)展到一個字符最多能有4字節(jié),所以能支持更多的字符集。

將Mysql的編碼從utf8轉(zhuǎn)換成utf8mb4。

需要 >= MySQL 5.5.3版本、從庫也必須是5.5的了、低版本不支持這個字符集、復(fù)制報錯

停止MySQL Server服務(wù)

修改 my.cnf或者mysql.ini

[client]
 default-character-set = utf8mb4

[mysql]
 default-character-set = utf8mb4

[mysqld]
 character-set-client-handshake = FALSE
 character-set-server = utf8mb4
 collation-server = utf8mb4_unicode_ci
 init_connect='SET NAMES utf8mb4'

重啟 MySQL Server、檢查字符集。

查看服務(wù)器字符集設(shè)置

mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| Variable_name | Value |
+--------------------------+--------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+--------------------------+--------------------+

查看數(shù)據(jù)庫字符集

mysql> select * from SCHEMATA where SCHEMA_NAME='ttlsa';
+--------------+-------------+----------------------------+------------------------+----------+
| CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH |
+--------------+-------------+----------------------------+------------------------+----------+
| def | ttlsa | utf8mb4 | utf8mb4_unicode_ci | NULL |
+--------------+-------------+----------------------------+------------------------+----------+

查看表字符集

mysql> select TABLE_SCHEMA,TABLE_NAME,TABLE_COLLATION from information_schema.TABLES;
+--------------------+----------------------------------------------------+--------------------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_COLLATION |
+--------------------+----------------------------------------------------+--------------------+

查看列字符集

mysql> select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLLATION_NAME from COLUMNS;
+--------------------+----------------------------------------------------+--------------------------------------------+--------------------+
| TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | COLLATION_NAME |
+--------------------+----------------------------------------------------+--------------------------------------------+--------------------+

轉(zhuǎn)換字符集語句

use information_schema;
SELECT concat("ALTER DATABASE `",table_schema,"` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;") as _sql 
FROM `TABLES` where table_schema like "DB_NAME" group by table_schema;
SELECT concat("ALTER TABLE `",table_schema,"`.`",table_name,"` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") as _sql 
FROM `TABLES` where table_schema like "DB_NAME" group by table_schema, table_name;
SELECT concat("ALTER TABLE `",table_schema,"`.`",table_name, "` CHANGE `",column_name,"` `",column_name,"` ",data_type,"(",character_maximum_length,") CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") as _sql 
FROM `COLUMNS` where table_schema like "DB_NAME" and data_type in ('varchar');
SELECT concat("ALTER TABLE `",table_schema,"`.`",table_name, "` CHANGE `",column_name,"` `",column_name,"` ",data_type," CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") as _sql 
FROM `COLUMNS` where table_schema like "DB_NAME" and data_type in ('text','tinytext','mediumtext','long

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

使MySQL能夠存儲emoji表情字符的設(shè)置教程_MySQL

使MySQL能夠存儲emoji表情字符的設(shè)置教程_MySQL:MySQL 需要支持 emoji 表情符號版本需要大于5.5.3,且字符集需要設(shè)置為utf8mb4 字符集。utf8mb4和utf8到底有什么區(qū)別呢?原來以往的mysql的utf8一個字符最多3字節(jié),而utf8mb4則擴(kuò)展到一個字符最多能有4字節(jié),所以能支持更多的字符集。將Mysql的編碼從u
推薦度:
標(biāo)簽: 保存 emoji emoji表情
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top