无忧启动论坛

标题: discuz迁移,高版本mysql 导入sql 文件失败(现在测试已导入已成功) [打印本页]

作者: wuyou    时间: 2018-5-24 23:20
标题: discuz迁移,高版本mysql 导入sql 文件失败(现在测试已导入已成功)
对一些非常规的论坛用户名,即含有 .  - _ ?  全角字母 !这些字符的,会报错。

如导入时提示:
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 日志文件,注意清理,不然可能会把 / 盘撑爆了,导致导入失败,整个运行速度极慢。
作者: fjzjk    时间: 2018-5-24 23:42
百度说这个提示是用户名这个键值有重复的
作者: wuyou    时间: 2018-5-25 06:30
可能的原因是字符集的问题,原本没有重复的,因为导入时有乱码,导致有重复(乱码重复)。
作者: holley2008    时间: 2018-5-25 08:13
wuyou 发表于 2018-5-25 06:30
可能的原因是字符集的问题,原本没有重复的,因为导入时有乱码,导致有重复(乱码重复)。

会不会是这个原因?
https://blog.csdn.net/k346k346/article/details/75267332
作者: wuyou    时间: 2018-5-25 08:21
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
作者: 熄灭的火焰    时间: 2018-5-25 08:23
如果是万网,别用他的数据库管理工具,有问题.换Navicat

亲自遇到的。http://www.zhangyoucai.com/44.html
作者: wuyou    时间: 2018-5-25 08:25
如果保留 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
作者: wuyou    时间: 2018-5-25 08:26
熄灭的火焰 发表于 2018-5-25 08:23
如果是万网,别用他的数据库管理工具,有问题.换Navicat

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

现在是在虚拟机下做测试,试图导入现有的论坛mysql 数据。
作者: wuyou    时间: 2018-5-25 08:26
虚拟机上服务器环境 centos 7.5 , mysql 8.0.11,  apache 2.46
作者: 熄灭的火焰    时间: 2018-5-25 08:35
2011?   后面这个问号有问题,可能有两个原因,
1你数据库里面的存的就是这个,可能由于某种原因导致变成这样。
2你导出SQL时的工具有问题,

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

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

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


还有一个终极解决办法,前提你是VPS或实体主机,就是找到数据库物理路径,直接复制过来。
作者: wuyou    时间: 2018-5-25 09:56
熄灭的火焰 发表于 2018-5-25 08:35
2011?   后面这个问号有问题,可能有两个原因,
1你数据库里面的存的就是这个,可能由于某种原因导致变成 ...

2011? 是实际存在的论坛用户名
作者: 邪恶海盗    时间: 2018-5-25 09:57
MySQL好像7还是8跟以前不一样的,看下官方有没有提供转换程序吧...
作者: wuyou    时间: 2018-5-25 09:59
熄灭的火焰 发表于 2018-5-25 08:35
2011?   后面这个问号有问题,可能有两个原因,
1你数据库里面的存的就是这个,可能由于某种原因导致变成 ...

问题应该出在字符集上,建表语句如果还是用DEFAULT CHARSET=gbk,出错提示是最少的。
作者: wuyou    时间: 2018-5-25 21:25
先在旧数据库中删除 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及乱码部分,与官方安装文件的建表语句一致,顺利导入。
作者: wuyou    时间: 2018-5-26 08:04
现在导入成功!

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

/var/lib/mysql/binlog.index


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




欢迎光临 无忧启动论坛 (http://bbs.wuyou.net/) Powered by Discuz! X3.3