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官方原版文件中,即可完成安装。
二、换服务器升级安装(内容更新中)
1.导出旧空间上数据库的表结构文件struct.sql 和 数据文件data.sql
mysqldump -d -u root -p$mysqlpass bbs > struct.sql mysqldump -t -u root -p$mysqlpass bbs --default-character-set=UTF8 > data.sql
2.修改表结构文件 struct.sql,
_ci结尾的校对集大小写不敏感,即不区分大小写,ci是 case insensitive, 即 "大小写不敏感", a 和 A 会在字符判断中会被当做一样的.
凡是在以前导入中提示 ERROR 1062 (23000): Duplicate entry 'xxxx' for key 'username' 之类的提示,往往出在选用不当的校对集引起的。
本次升级调试时使用了_ci的校对集,就遇到这个问题,象 'Avaloń' 与 'avalon' 被认为是重复,导致导入失败。
校对集 COLLATE=utf8mb4_bin 是区分大小写,可以防止旧库中有KEY属性的论坛用户名ABC、abc导入时被认为是重复的问题。
修改struct.sql
DEFAULT CHARSET=gbk 全部改成 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
varchar(255) 修改值
char(255) 修改值
callsed 文件内容
/^CREATE TABLE `pre_common_addon`/,/^) ENGINE=MyISAM/s/`key` varchar(255)/`key` varchar(250)/
/^CREATE TABLE `pre_common_admincp_perm`/,/^) ENGINE=MyISAM/s/`perm` varchar(255)/`perm` varchar(244)/
/^CREATE TABLE `pre_common_advertisement_custom`/,/^) ENGINE=MyISAM/s/`name` varchar(255)/`name` varchar(250)/
/^CREATE TABLE `pre_common_cache`/,/^) ENGINE=MyISAM/s/`cachekey` varchar(255)/`cachekey` varchar(250)/
/^CREATE TABLE `pre_common_card`/,/^) ENGINE=MyISAM/s/`id` char(255)/`id` char(250)/
/^CREATE TABLE `pre_common_member_profile_setting`/,/^) ENGINE=MyISAM/s/`fieldid` varchar(255)/`fieldid` varchar(250)/
/^CREATE TABLE `pre_common_member_security`/,/^) ENGINE=MyISAM/s/`fieldid` varchar(255)/`fieldid` varchar(242)/
/^CREATE TABLE `pre_common_setting`/,/^) ENGINE=MyISAM/s/`skey` varchar(255)/`skey` varchar(250)/
/^CREATE TABLE `pre_forum_groupfield`/,/^) ENGINE=MyISAM/s/`type` varchar(255)/`type` varchar(242)/
/^CREATE TABLE `pre_home_favorite`/,/^) ENGINE=MyISAM/s/`idtype` varchar(255)/`idtype` varchar(232)/
/^CREATE TABLE `pre_mobile_setting`/,/^) ENGINE=MyISAM/s/`skey` varchar(255)/`skey` varchar(250)/
/^CREATE TABLE `pre_portal_topic`/,/^) ENGINE=MyISAM/s/`name` varchar(255)/`name` varchar(250)/
/^CREATE TABLE `cdb_uc_badwords`/,/^) ENGINE=MyISAM/s/`find` varchar(255)/`find` varchar(250)/
s/DEFAULT CHARSET=gbk/DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin/
在linux shell 下执行以下命令进行替换
sed -i -f callsed struct.sql
也可以在mysql 命令行下先修改原库(注意先备份数据库)
USE bbs; ALTER TABLE `pre_common_addon` MODIFY COLUMN `key` varchar(250); ALTER TABLE `pre_common_admincp_perm` MODIFY COLUMN `perm` varchar(244); ALTER TABLE `pre_common_advertisement_custom` MODIFY COLUMN `name` varchar(250); ALTER TABLE `pre_common_cache` MODIFY COLUMN `cachekey` varchar(250); ALTER TABLE `pre_common_card` MODIFY COLUMN `id` char(250); ALTER TABLE `pre_common_member_profile_setting` MODIFY COLUMN `fieldid` varchar(250); ALTER TABLE `pre_common_member_security` MODIFY COLUMN `fieldid` varchar(242); ALTER TABLE `pre_common_setting` MODIFY COLUMN `skey` varchar(250); ALTER TABLE `pre_forum_groupfield` MODIFY COLUMN `type` varchar(242); ALTER TABLE `pre_home_favorite` MODIFY COLUMN `idtype` varchar(232); ALTER TABLE `pre_mobile_setting` MODIFY COLUMN `skey` varchar(250); ALTER TABLE `pre_portal_topic` MODIFY COLUMN `name` varchar(250); ALTER TABLE `cdb_uc_badwords` MODIFY COLUMN `find` varchar(250);
3.在新空间的 mysql命令行下,导入struct.sql 和 数据文件data.sql
USE bbs; SOURCE struct.sql; SOURCE data.sql
4.恢复旧空间的web数据库到新空间上,修改以下文件,将第一次出现连接库的'gbk' 改为 'utf8mb4'.每个文件只改一处。
config/config_global.php
config/config_global.php
uc_server/data/config.inc.php
5.按官方升级要求,上传官方版文件替换,进后台 > 工具 > 更新缓存。
另外还有source/class/table/下面三个文件需要更新,具体见本帖上方发的全新安装补丁包中提取。
table_common_usergroup.php
table_forum_announcement.php
table_forum_forum.php
6.界面 > 编辑器设置 > Discuz!代码,删除那些不可用的标签,可解决因使用Discuz标签而导致帖子内容无法正常显示的问题。
7.升级安装成功
目前仍存在问题:编辑正在投放的广告位时无内容显示。
这次还发现有一个分页标签,点下方的2可以看下一页,一直没用过这个标签,第一次用。
如果ENGINE使用InnoDB,则修改
ENGINE=MyISAM 全部替换为 ENGINE=InnoDB
并将所有有auto_increment 属性的,加为KEY。
如 id 有auto_increment属性,则在相应段加上一行 KEY `id` (`id`), (如果已有完全相同这一行就不要加)
以下是这次解决问题过程,没兴趣的可不看:
1.常规安装,然后导出数据库,修改默认字符集
sed -i '/DEFAULT CHARSET=utf8[^m]/s/DEFAULT CHARSET=utf8/&mb4/' bbs.sql
2.使用ENGINE=MyISAM ,如果直接导入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');
再进行安装。
现在发帖,就可以正常使用表情符了,用户名都可以用表情符注册!
还没有评论,来说两句吧...