无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站投放广告、加入VIP会员,请联系 微信:wuyouceo
查看: 7237|回复: 14
打印 上一主题 下一主题

[分享] discuz迁移,高版本mysql 导入sql 文件失败(现在测试已导入已成功)

  [复制链接]
跳转到指定楼层
1#
发表于 2018-5-24 23:20:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
对一些非常规的论坛用户名,即含有 .  - _ ?  全角字母 !这些字符的,会报错。

如导入时提示:
ERROR 1062 (23000) at line 406: Duplicate entry '......' for key 'username'
上面的 ...... 是用户名(discuz程序应该对用户名取名进行限制一下)

困惑中,难道非得清理这些用户?

后续进展:
目前解决办法:

先在旧数据库中删除 2011? 和 Cappuccīnó 这两个用户名(这是针对我的论坛数据),导出utf8编码的sql文件后,修改 bbs.sql 文件中的DEFAULT CHARSET=gbk 改为 DEFAULT CHARSET=utf8,
sed -i 's/DEFAULT CHARSET=gbk/DEFAULT CHARSET=utf8/g' bbs.sql

经检查,sql文件中以下几个表的建表语句中 COMMENT 后有乱码 (备注一下,现空间已做处理,以后不再关注这个)

pre_security_evilpost
pre_security_eviluser
pre_security_failedlog

如 `id` int(10) unsigned NOT NULL AUTO_INCREMENT primary key COMMENT '乱码部分',

删除 COMMENT 及乱码部分,与官方安装文件的建表语句一致,顺利导入。
  1. alter table pre_security_evilpost modify `pid` int(10) unsigned NOT NULL;
  2. alter table pre_security_evilpost modify `tid` mediumint(8) unsigned NOT NULL default '0';
  3. alter table pre_security_evilpost modify `type` tinyint(1) NOT NULL default '0';
  4. alter table pre_security_evilpost modify `evilcount` int(10) NOT NULL default '0';
  5. alter table pre_security_evilpost modify `eviltype` mediumint(8) unsigned NOT NULL default '0';
  6. alter table pre_security_evilpost modify `createtime` int(10) unsigned NOT NULL default '0';
  7. alter table pre_security_evilpost modify `operateresult` tinyint(1) unsigned NOT NULL default '0';
  8. alter table pre_security_evilpost modify `isreported` tinyint(1) NOT NULL default '0';

  9. alter table pre_security_eviluser modify `uid` int(10) unsigned NOT NULL;
  10. alter table pre_security_eviluser modify `evilcount` int(10) NOT NULL default '0';
  11. alter table pre_security_eviluser modify `eviltype` mediumint(8) unsigned NOT NULL default '0';
  12. alter table pre_security_eviluser modify `createtime` int(10) unsigned NOT NULL default '0';
  13. alter table pre_security_eviluser modify `operateresult` tinyint(1) unsigned NOT NULL default '0';
  14. alter table pre_security_eviluser modify `isreported` tinyint(1) NOT NULL default '0';

  15. alter table pre_security_failedlog modify `id` int(11) NOT NULL auto_increment;
  16. alter table pre_security_failedlog modify `reporttype` char(20) NOT NULL;
  17. alter table pre_security_failedlog modify `tid` int(10) unsigned NOT NULL default '0';
  18. alter table pre_security_failedlog modify `pid` int(10) unsigned NOT NULL default '0';
  19. alter table pre_security_failedlog modify `uid` int(10) unsigned NOT NULL default '0';
  20. alter table pre_security_failedlog modify `failcount` int(10) unsigned NOT NULL default '0';
  21. alter table pre_security_failedlog modify `createtime` int(10) unsigned NOT NULL default '0';
  22. alter table pre_security_failedlog modify `posttime` int(10) unsigned NOT NULL default '0';
  23. alter table pre_security_failedlog modify `delreason` char(255) NOT NULL;
  24. alter table pre_security_failedlog modify `scheduletime` int(10) unsigned NOT NULL default '0';
  25. alter table pre_security_failedlog modify `lastfailtime` int(10) unsigned NOT NULL default '0';
  26. alter table pre_security_failedlog modify `extra1` int(10) unsigned NOT NULL;
  27. alter table pre_security_failedlog modify `extra2` char(255) NOT NULL default '0';
复制代码


再导入旧网站web数据,上传discuzX 3.4升级文件,然后在三个配置中的 gbk 全改为utf8,更新mysql 连接密码(如果密码不变不用改)

一个小插曲,导入mysql 时会产生大量mysql log 日志文件,注意清理,不然可能会把 / 盘撑爆了,导致导入失败,整个运行速度极慢。
2#
发表于 2018-5-24 23:42:03 | 只看该作者
百度说这个提示是用户名这个键值有重复的
回复

使用道具 举报

3#
 楼主| 发表于 2018-5-25 06:30:03 | 只看该作者
可能的原因是字符集的问题,原本没有重复的,因为导入时有乱码,导致有重复(乱码重复)。

点评

会不会是这个原因? https://blog.csdn.net/k346k346/article/details/75267332  详情 回复 发表于 2018-5-25 08:13
回复

使用道具 举报

4#
发表于 2018-5-25 08:13:47 | 只看该作者
wuyou 发表于 2018-5-25 06:30
可能的原因是字符集的问题,原本没有重复的,因为导入时有乱码,导致有重复(乱码重复)。

会不会是这个原因?
https://blog.csdn.net/k346k346/article/details/75267332

点评

昨天试过这个方法,没有用。 今天先试着将mysql gbk 表导出为utf8的bbs.sql,然后修改bbs.sql 文件中的 DEFAULT CHARSET=gbk 为 DEFAULT CHARSET=utf8 再进行导入,提示如下: ERROR 1062 (23000) at line 394:  详情 回复 发表于 2018-5-25 08:21
回复

使用道具 举报

5#
 楼主| 发表于 2018-5-25 08:21:32 | 只看该作者
holley2008 发表于 2018-5-25 08:13
会不会是这个原因?
https://blog.csdn.net/k346k346/article/details/75267332

昨天试过这个方法,没有用。
今天先试着将mysql gbk 表导出为utf8的bbs.sql,然后修改bbs.sql 文件中的 DEFAULT CHARSET=gbk 为 DEFAULT CHARSET=utf8 再进行导入,提示如下:

ERROR 1062 (23000) at line 394: Duplicate entry '2011?' for key 'username'
ERROR 1062 (23000) at line 408: Duplicate entry 'Cappuccīnó' for key 'username'
ERROR 1062 (23000) at line 459: Duplicate entry '1-2011?' for key 'PRIMARY'
ERROR 1062 (23000) at line 2719: Duplicate entry '2011?' for key 'username'
ERROR 1062 (23000) at line 2734: Duplicate entry 'Cappuccīnó' for key 'username'
ERROR 3507 (HY000) at line 15639: Failed to update columns dictionary object.
ERROR 1146 (42S02) at line 15659: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 1146 (42S02) at line 15660: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 1146 (42S02) at line 15661: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 1146 (42S02) at line 15662: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 1146 (42S02) at line 15663: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 1146 (42S02) at line 15664: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 3507 (HY000) at line 15674: Failed to update columns dictionary object.
ERROR 1146 (42S02) at line 15690: Table 'bbs.pre_security_eviluser' doesn't exist
ERROR 1146 (42S02) at line 15691: Table 'bbs.pre_security_eviluser' doesn't exist
ERROR 1146 (42S02) at line 15692: Table 'bbs.pre_security_eviluser' doesn't exist
ERROR 1146 (42S02) at line 15693: Table 'bbs.pre_security_eviluser' doesn't exist
ERROR 3507 (HY000) at line 15703: Failed to update columns dictionary object.
ERROR 1146 (42S02) at line 15727: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15728: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15729: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15730: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15731: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15732: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15733: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15734: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15735: Table 'bbs.pre_security_failedlog' doesn't exist
回复

使用道具 举报

6#
发表于 2018-5-25 08:23:25 | 只看该作者
如果是万网,别用他的数据库管理工具,有问题.换Navicat

亲自遇到的。http://www.zhangyoucai.com/44.html

点评

现在是在虚拟机下做测试,试图导入现有的论坛mysql 数据。  详情 回复 发表于 2018-5-25 08:26
回复

使用道具 举报

7#
 楼主| 发表于 2018-5-25 08:25:07 | 只看该作者
如果保留 bbs.sql 文件中的 DEFAULT CHARSET=gbk 进行导入,提示如下:

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1062 (23000) at line 394: Duplicate entry '2011?' for key 'username'
ERROR 1062 (23000) at line 459: Duplicate entry '1-2011?' for key 'PRIMARY'
ERROR 1062 (23000) at line 2719: Duplicate entry '2011?' for key 'username'
ERROR 3507 (HY000) at line 15639: Failed to update columns dictionary object.
ERROR 1146 (42S02) at line 15659: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 1146 (42S02) at line 15660: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 1146 (42S02) at line 15661: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 1146 (42S02) at line 15662: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 1146 (42S02) at line 15663: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 1146 (42S02) at line 15664: Table 'bbs.pre_security_evilpost' doesn't exist
ERROR 3507 (HY000) at line 15674: Failed to update columns dictionary object.
ERROR 1146 (42S02) at line 15690: Table 'bbs.pre_security_eviluser' doesn't exist
ERROR 1146 (42S02) at line 15691: Table 'bbs.pre_security_eviluser' doesn't exist
ERROR 1146 (42S02) at line 15692: Table 'bbs.pre_security_eviluser' doesn't exist
ERROR 1146 (42S02) at line 15693: Table 'bbs.pre_security_eviluser' doesn't exist
ERROR 3507 (HY000) at line 15703: Failed to update columns dictionary object.
ERROR 1146 (42S02) at line 15727: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15728: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15729: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15730: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15731: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15732: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15733: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15734: Table 'bbs.pre_security_failedlog' doesn't exist
ERROR 1146 (42S02) at line 15735: Table 'bbs.pre_security_failedlog' doesn't exist
回复

使用道具 举报

8#
 楼主| 发表于 2018-5-25 08:26:03 | 只看该作者
熄灭的火焰 发表于 2018-5-25 08:23
如果是万网,别用他的数据库管理工具,有问题.换Navicat

亲自遇到的。http://www.zhangyoucai.com/44.html

现在是在虚拟机下做测试,试图导入现有的论坛mysql 数据。
回复

使用道具 举报

9#
 楼主| 发表于 2018-5-25 08:26:44 | 只看该作者
虚拟机上服务器环境 centos 7.5 , mysql 8.0.11,  apache 2.46
回复

使用道具 举报

10#
发表于 2018-5-25 08:35:52 | 只看该作者
2011?   后面这个问号有问题,可能有两个原因,
1你数据库里面的存的就是这个,可能由于某种原因导致变成这样。
2你导出SQL时的工具有问题,

排查:
先查看原数据库的的对应记录是否同样是问号,
换个数据库管理工具再看一下
如果其中有一个正常,那么就是工具的问题,如果两个都是问号,那么可能就是数据的问题了,跟工具无关,

遇到确实是问号的情况,去论坛后台找到这两个账号,核对一下,是否同样的问号。

这样排查完了可能会有所发现。


还有一个终极解决办法,前提你是VPS或实体主机,就是找到数据库物理路径,直接复制过来。

点评

问题应该出在字符集上,建表语句如果还是用DEFAULT CHARSET=gbk,出错提示是最少的。  详情 回复 发表于 2018-5-25 09:59
2011? 是实际存在的论坛用户名  详情 回复 发表于 2018-5-25 09:56

评分

参与人数 1无忧币 +5 收起 理由
q8155128 + 5 神马都是浮云 火焰大师就是牛......

查看全部评分

回复

使用道具 举报

11#
 楼主| 发表于 2018-5-25 09:56:04 | 只看该作者
熄灭的火焰 发表于 2018-5-25 08:35
2011?   后面这个问号有问题,可能有两个原因,
1你数据库里面的存的就是这个,可能由于某种原因导致变成 ...

2011? 是实际存在的论坛用户名
回复

使用道具 举报

12#
发表于 2018-5-25 09:57:35 | 只看该作者
MySQL好像7还是8跟以前不一样的,看下官方有没有提供转换程序吧...
回复

使用道具 举报

13#
 楼主| 发表于 2018-5-25 09:59:23 | 只看该作者
熄灭的火焰 发表于 2018-5-25 08:35
2011?   后面这个问号有问题,可能有两个原因,
1你数据库里面的存的就是这个,可能由于某种原因导致变成 ...

问题应该出在字符集上,建表语句如果还是用DEFAULT CHARSET=gbk,出错提示是最少的。
回复

使用道具 举报

14#
 楼主| 发表于 2018-5-25 21:25:17 | 只看该作者
先在旧数据库中删除 2011? 这个用户名,导出utf8编码的sql文件后,保留 bbs.sql 文件中的 DEFAULT CHARSET=gbk 不变,
经检查,sql文件中以下几个表的建表语句中 COMMENT 后有乱码

Table 'bbs.pre_security_evilpost
bbs.pre_security_eviluser
bbs.pre_security_failedlog

如 `id` int(10) unsigned NOT NULL AUTO_INCREMENT primary key COMMENT '乱码部分',

删除COMMENT及乱码部分,与官方安装文件的建表语句一致,顺利导入。
回复

使用道具 举报

15#
 楼主| 发表于 2018-5-26 08:04:31 | 只看该作者
现在导入成功!

一个小插曲,导入mysql 时会产生大量mysql log 日志文件,每个文件最大可达到1GB
/var/lib/mysql/binlog.000001
/var/lib/mysql/binlog.000002
....

/var/lib/mysql/binlog.index


注意清理,要把binlog.index 一起清空,不然可能会把 / 盘撑爆了,导致导入失败,整个运行速度极慢。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2025-12-11 03:00

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表