当前位置: 首页 > news >正文

政务服务网站建设技术因素一级消防工程师考试

政务服务网站建设技术因素,一级消防工程师考试,做网站需要什么条件,用tornado做网站前言 呵呵 最近同事有这样的一个需求 需要将 库1 的一张表 复制到 库2 然后 我想到了 之前一直使用的通过复制这个库的 data 文件来进行数据迁移的思路, 是需要复制这个 库对应的 data 目录下的数据文件, 以及 ibdata1 文件 然后 我又在想 这里的场景能否也使用这里的额方式…

前言

呵呵 最近同事有这样的一个需求

需要将 库1 的一张表 复制到 库2

然后 我想到了 之前一直使用的通过复制这个库的 data 文件来进行数据迁移的思路, 是需要复制这个 库对应的 data 目录下的数据文件, 以及 ibdata1 文件

然后 我又在想 这里的场景能否也使用这里的额方式呢 ?

我直接将 库1 的 $table.idb, $table.frm 复制到 库2, 然后 重启 mysql 服务器 是否可行??

然后 尝试了一下, 呵呵 直接 mysql 服务启动不起来了

而且 当时这个库还是有很多其他同事在使用, 因此 也是比较难受的

当时处理的方式是, 回滚了 $table.ibd, $table.frm 以及删除了 mysql-bin.index 的文件

当然 我目前还不知道 为什么这个文件 会对 mysql 服务启动造成影响, 呵呵 后面能够复现再回来探究吧

 

 

为什么 通过从 库1 复制 *.ibd 到 库2 导致 mysql 启动报错

日志信息如下, 不同的 mysql 版本错误信息可能会有所差异, 我这里复现的错误信息 和 出现问题的机器的错误信息就有所不同 

我这里复现的处理方式是 删除 test02 中的 user.idb, user.frm, 并且将 test 中的 user.idb, user.frm 复制到 test02 

2022-05-01 18:03:42 3782 [Note] InnoDB: The log sequence numbers 1745148 and 1745148 in ibdata files do not match the log sequence number 2805972 in the ib_logfiles!
2022-05-01 18:03:42 3782 [Note] InnoDB: Database was not shutdown normally!
2022-05-01 18:03:42 3782 [Note] InnoDB: Starting crash recovery.
2022-05-01 18:03:42 3782 [Note] InnoDB: Reading tablespace information from the .ibd files...
2022-05-01 18:06:23 3782 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace test/user uses space ID: 6 at filepath: ./test/user.ibd. Cannot open tablespace test02/user which uses space ID: 6 at filepath: ./test02/user.ibd
2022-05-01 18:06:23 10ef305c0  InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directories yourself, InnoDB does not create them.
InnoDB: Error: could not open single-table tablespace file ./test02/user.ibd
InnoDB: We do not continue the crash recovery, because the table may become
InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.
InnoDB: To fix the problem and start mysqld:
InnoDB: 1) If there is a permission problem in the file and mysqld cannot
InnoDB: open the file, you should modify the permissions.
InnoDB: 2) If the table is not needed, or you can restore it from a backup,
InnoDB: then you can remove the .ibd file, and InnoDB will do a normal
InnoDB: crash recovery and ignore that table.
InnoDB: 3) If the file system or the disk is broken, and you cannot remove
InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf
InnoDB: and force InnoDB to continue crash recovery here.

 

从日志中可以大致看出的是 test/user.idb 和 test02/user.idb 的 spaceId 都是 6, 然后 加载的时候出现了问题 

然后 从逻辑上 spaceId 应该是一一映射到一个数据表文件的, mysql 校验的时候报错 

按照 正常的理解, 应该是 删除掉 test02 下面的 user.idb, user.frm 或者 回滚 test02 下面的 user.idb, user.frm 就行 

 

 

从 mysql 源码来看这个问题

报错的地方是在加载 单个表空间 的时候, 校验存在问题 

根据 test02/user.ibd 的 fileSpace.id 来查询已有的 fileSpace 中是否存在 fileSpace, 发现已经存在一个 test/user.ibd 的 fileSpace, 然后验证不通过, 报错 

a407bcbb4a3a42be8c0f3a3c99908d4e.png

 

fileSpace.id 是怎么加载?

从 idb 文件中加载 第一页[16k] 的数据, 然后读取 pageIdOffset 的数据作为 spaceId, 比如这里的 test02/user.ibd + 34[pageOffset] 为 6 作为 pageId 

2e722aee6f34442aa7894da5d109c4ff.png

 

如下打开 test02/user.idb 找到偏移为 34 的连续四个字节, 0x00000006, spaceId 为 0x06 

8ce8e9822f584c81b2359f0a2c7a3247.png 

 

偏移为 38 的连续四个字节也是 spaceId 

这部分数据称之为 spaceHeader, 下面的备注也写清楚了, 这个数据结构仅仅在第一页存储并使用

cc8f4258ff8c4f4fa2bc0b2ad3a93f43.png

 

 

fileSpace 的维护?

上面校验的步骤, 我们看到了这个 fileSpace 的使用的地方, 根据 fileSpace.id 查询 fileSpace 

那么 加载 fileSpace 之后, 将表空间添加到 fileSpace 的地方又在哪里呢?  5f1d39951f0b470abbcf5b8f9eb3b4e6.png

 

将表空间添加到 fileSpace 的地方又在哪里呢? 

是在加载表空间所有的验证, 准备工作都完成了之后, 将 space 注册到 fil_system.spaces 中 

ac53e0cbaaaa44f0adc89b40f96bd1fc.png 

 

回溯问题

总结一下 就是 每一个数据表的 spaceId 期望应该是唯一的, 然后 硬盘上是存储在 对应的数据表文件的第一个 page 上面 

然后 因为我们这里是直接将 库1 的 $table.idb 复制到了 库2, 这两个 $table.idb 文件的 spaceId 是相同的[因为是复制过来的]

然后导致了 mysql 加载 filelSpace 的时候出现了问题 

 

查询数据表的 tabSpace 的数据, 可以通过 INNODB_SYS_TABLESPACE 进行查询 

比如如下的 test/user 数据表的 spaceId 为 6, 和上面调试过程中得到的 spaceId 是一致的 

然后 原有的 test02/user 数据表的 spaceId 为 24 

我这里本地环境处理方式是 直接将 test02/user.* 回滚回去, 然后 重启数据库即可 

6840c561d6984e3ab2a4ab5c7cacd9f7.png

 

 

 

 

 

http://www.mmbaike.com/news/57985.html

相关文章:

  • 成都百度推广公司联系方式seo教程免费分享
  • 在百度上免费做网站页面关键词提取
  • 专业做包装设计网站关键词查询的五种常用工具
  • 门户网站系统程序软文网站推荐
  • 网站如何做301跳转建立公司网站需要多少钱
  • WordPress为什么进不去seo宣传网站
  • 镇江网站设计开发公司电话百度seo排名推广
  • ftp客户端软件超级优化大师
  • 专业做网站开发费用广州百度提升优化
  • 沈阳网站制作公司网站新域名查询
  • 网站开发需要什么费用网站设计制作
  • cdr可不可做网站全文搜索引擎有哪些
  • 太原制作响应式网站网站关键词排名如何提升
  • 网站的建设是什么他达那非副作用太强了
  • 网站制作答辩ppt怎么做武汉百度seo排名
  • 网站建设评分标准建设网站的基本流程
  • 手机网站列表模板珠海百度推广优化排名
  • java做网站和php做网站seo站长查询
  • 合肥外贸网站建设公司价格网站seo源码
  • 怎么在悉尼做网站宁波网络营销推广咨询报价
  • 龙岗网站建设定制开发seo服务靠谱吗
  • 做专业网站营销型网站建设目标
  • 网站地图作用做网站公司
  • wordpress 不显示发布时间免费seo优化工具
  • 济南手工网站建设阿里云免费建站
  • 广告案例网站百度搜索智能精选入口
  • 一个人做企业网站要多少天百度公司官网入口
  • 建筑工程论坛网网站seo什么意思
  • wordpress样式表颜色搜索引擎优化公司排行
  • 有做模仿易企秀网站吗技能培训网站