discuz论坛数据库改用utf8mb4字符集,正常使用emoji表情符号的教程方案

10个月前 ( 04-06 ) 541 0条评论

官方discuzX 3.4 默认是utf8,安装后无法发一些表情符。

现在做测试改成 utf8mb4.
测试机环境
centos 7.5
mysql 8.0.11
php 7.2.5
apache 2.4.6

一、全新安装

下载补丁文件,替换加入到discuzX 3.4  2018.01.01官方原版文件中,即可完成安装,可以正常发表情符

文件下载地址 http://bbs.wuyou.net/forum.php?mod=viewthread&tid=409353&extra=page%3D1

---------------------------------------------------------------

以下是这次解决问题过程,没兴趣的可不看:

1.常规安装,然后导出数据库,修改默认字符集

sed -i '/DEFAULT CHARSET=utf8[^m]/s/DEFAULT CHARSET=utf8/&mb4/' bbs.sql


2.如果直接导入bbs.sql,会出错,提示如下:

ERROR 1071 (42000) at line 104: Specified key was too long; max key length is 1000 bytes
ERROR 1146 (42S02) at line 115: Table 'bbs.pre_common_admincp_perm' doesn't exist
ERROR 1146 (42S02) at line 116: Table 'bbs.pre_common_admincp_perm' doesn't exist
ERROR 1146 (42S02) at line 117: Table 'bbs.pre_common_admincp_perm' doesn't exist
ERROR 1146 (42S02) at line 118: Table 'bbs.pre_common_admincp_perm' doesn't exist
ERROR 1071 (42000) at line 631: Specified key was too long; max key length is 1000 bytes
ERROR 1146 (42S02) at line 643: Table 'bbs.pre_common_cache' doesn't exist
ERROR 1146 (42S02) at line 644: Table 'bbs.pre_common_cache' doesn't exist
ERROR 1146 (42S02) at line 645: Table 'bbs.pre_common_cache' doesn't exist
ERROR 1071 (42000) at line 655: Specified key was too long; max key length is 1000 bytes
ERROR 1146 (42S02) at line 677: Table 'bbs.pre_common_card' doesn't exist
ERROR 1146 (42S02) at line 678: Table 'bbs.pre_common_card' doesn't exist
ERROR 1146 (42S02) at line 679: Table 'bbs.pre_common_card' doesn't exist
ERROR 1071 (42000) at line 1831: Specified key was too long; max key length is 1000 bytes
ERROR 1146 (42S02) at line 1857: Table 'bbs.pre_common_member_profile_setting' doesn't exist
ERROR 1146 (42S02) at line 1858: Table 'bbs.pre_common_member_profile_setting' doesn't exist
ERROR 1146 (42S02) at line 1859: Table 'bbs.pre_common_member_profile_setting' doesn't exist
ERROR 1146 (42S02) at line 1860: Table 'bbs.pre_common_member_profile_setting' doesn't exist
ERROR 1071 (42000) at line 1870: Specified key was too long; max key length is 1000 bytes
ERROR 1146 (42S02) at line 1888: Table 'bbs.pre_common_member_security' doesn't exist
ERROR 1146 (42S02) at line 1889: Table 'bbs.pre_common_member_security' doesn't exist
ERROR 1146 (42S02) at line 1890: Table 'bbs.pre_common_member_security' doesn't exist
ERROR 1071 (42000) at line 2673: Specified key was too long; max key length is 1000 bytes
ERROR 1146 (42S02) at line 2684: Table 'bbs.pre_common_setting' doesn't exist
ERROR 1146 (42S02) at line 2685: Table 'bbs.pre_common_setting' doesn't exist
ERROR 1146 (42S02) at line 2686: Table 'bbs.pre_common_setting' doesn't exist
ERROR 1146 (42S02) at line 2687: Table 'bbs.pre_common_setting' doesn't exist
ERROR 1071 (42000) at line 4800: Specified key was too long; max key length is 1000 bytes
ERROR 1146 (42S02) at line 4816: Table 'bbs.pre_forum_groupfield' doesn't exist
ERROR 1146 (42S02) at line 4817: Table 'bbs.pre_forum_groupfield' doesn't exist
ERROR 1146 (42S02) at line 4818: Table 'bbs.pre_forum_groupfield' doesn't exist
ERROR 1071 (42000) at line 7101: Specified key was too long; max key length is 1000 bytes
ERROR 1146 (42S02) at line 7120: Table 'bbs.pre_home_favorite' doesn't exist
ERROR 1146 (42S02) at line 7121: Table 'bbs.pre_home_favorite' doesn't exist
ERROR 1146 (42S02) at line 7122: Table 'bbs.pre_home_favorite' doesn't exist
ERROR 1071 (42000) at line 7797: Specified key was too long; max key length is 1000 bytes
ERROR 1146 (42S02) at line 7808: Table 'bbs.pre_mobile_setting' doesn't exist
ERROR 1146 (42S02) at line 7809: Table 'bbs.pre_mobile_setting' doesn't exist
ERROR 1146 (42S02) at line 7810: Table 'bbs.pre_mobile_setting' doesn't exist
ERROR 1146 (42S02) at line 7811: Table 'bbs.pre_mobile_setting' doesn't exist
ERROR 1071 (42000) at line 8567: Specified key was too long; max key length is 1000 bytes
ERROR 1146 (42S02) at line 8582: Table 'bbs.pre_ucenter_badwords' doesn't exist
ERROR 1146 (42S02) at line 8583: Table 'bbs.pre_ucenter_badwords' doesn't exist
ERROR 1146 (42S02) at line 8584: Table 'bbs.pre_ucenter_badwords' doesn't exist

处理方法1:
-----------------
根据 ERROR 1071 (42000) at line 104: Specified key was too long; max key length is 1000 bytes 提示,查找 bbs.sql 文件相应行104行及后续10行:

sed -n '104,114p' bbs.sql


CREATE TABLE `pre_common_admincp_perm` (
  `cpgroupid` smallint(6) unsigned NOT NULL,
  `perm` varchar(255) NOT NULL,
  UNIQUE KEY `cpgroupperm` (`cpgroupid`,`perm`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `pre_common_admincp_perm`
--

可以看出 UNIQUE KEY `cpgroupperm` (`cpgroupid`,`perm`) 定义的长度 是 (6+255) * 4 > 1000 , 只要把`perm` varchar 值改小,使其总和不要超过1000即可。
现在改为 230.

sed -i '106s/255/230/' bbs.sql


其他类似提示的行做同样的修改,成功导入数据库。

处理方法2:
-----------------
根据上面提示中出现的所有表,对安装文件先做处理

pre_ucenter_badwords 表:对应查 uc_badwords  ,从 uc_server/install/uc.sql  修改
其他表在 install/data/install.sql 修改

官方原始文件 config 下的所有.php文件中的 utf8 都改为 utf8mb4
注意 utf-8 不要改动。

改好以下文件
install/data/install.sql
uc_server/install/uc.sql

修改 install/include/install_var.php

define('DBCHARSET', 'utf8');     改为    define('DBCHARSET', 'utf8mb4');

再进行安装。


现在发帖,就可以正常使用表情符了!

文章版权及转载声明

本文作者:符文浩 网址:http://blog.haozi.org/post/273.html发布于 10个月前 ( 04-06 )
文章转载或复制请以超链接形式并注明出处。

发表评论

评论列表 (暂无评论,541人围观)参与讨论

还没有评论,来说两句吧...

取消
支付宝二维码
支付宝二维码
微信二维码