MySQL数据库升级到8.0+以后Discuz! 后台更新缓存时出现以下错误
(1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'system>0' at line 1
SELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0
(1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups = '' AND starttime<=1532077291 AND (endtime>=1532077291 OR endtime=0) ORD' at line 1
SELECT * FROM forum_announcement WHERE type!=2 AND groups = '' AND starttime<=1532077291 AND (endtime>=1532077291 OR endtime=0) ORDER BY displayorder, starttime DESC, id DESC LIMIT 1
因为MySQL 8.0+将system和groups作为了关键字,所以不能直接在SQL中将system和groups这两个词作为数据库、数据表、数据表字段中的任意一种使用,如果数据库名或数据表名或数据表字段名使用了system或groups作为名字,必须使用一对反引号引用起来。写作`system`或`groups`。
具体到以上错误,第一个错误需要找到Discuz!目录中的source\class\table\table_common_usergroup.php,比如
D:\server\www\wuxiancheng.cn\source\class\table\table_common_usergroup.php
将文件中所有的system全部改成`system`,保存后重新上传到服务器的相同目录即可。
第二个错误需要找到Discuz!目录下中的source\class\table\table_forum_announcement.php,比如
D:\server\www\wuxiancheng.cn\source\class\table\table_forum_announcement.php
将文件中所有的groups全部改为`groups`,保存后重新上传到服务器的相同目录即可。
如果在MySQL 8+环境下安装Discuz!,在安装前需要给install\data\install.sql文件中没有加引号的所有system逐一添加一对反引号保存重新上传到服务器的相同目录,否则也会出现SQL语法错误。
为了避免语法错误,在写SQL语句时,一定要为所有的数据库名、数据表名、数据表字段名全部添加一对反引号,像Discuz!这样的写法是很不提倡的。
MySQL 8.0新增的关键字和保留词为:ACTIVE, ADMIN, BUCKETS, CLONE, COMPONENT, CUME_DIST, DEFINITION, DENSE_RANK, DESCRIPTION, EMPTY, EXCEPT, EXCLUDE, FIRST_VALUE, FOLLOWING, GEOMCOLLECTION, GET_MASTER_PUBLIC_KEY, GROUPING, GROUPS, HISTOGRAM, HISTORY, INACTIVE, INVISIBLE, JSON_TABLE, LAG, LAST_VALUE, LEAD, LOCKED, MASTER_PUBLIC_KEY_PATH, NESTED, NOWAIT, NTH_VALUE, NTILE, NULLS, OF, OPTIONAL, ORDINALITY, ORGANIZATION, OTHERS, OVER, PATH, PERCENT_RANK, PERSIST, PERSIST_ONLY, PRECEDING, PROCESS, RANK, RECURSIVE, REFERENCE, RESOURCE, RESPECT, RESTART, REUSE, ROLE, ROW_NUMBER, SECONDARY_ENGINE, SECONDARY_LOAD, SECONDARY_UNLOAD, SKIP, SRID, SYSTEM, THREAD_PRIORITY, TIES, UNBOUNDED, VCPU, VISIBLE, WINDOW. |
|