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

美团网站网站建设发展网页搜索引擎大全

美团网站网站建设发展,网页搜索引擎大全,做企业网站找谁,武汉双军网站建设公司前言 呵呵 最近同事有这样的一个需求 需要将 库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.tj-hxxt.cn/news/22475.html

相关文章:

  • 茌平做创建网站公司平台推广方式方法是什么
  • 做精酿啤酒购买的网站宁波seo怎么做引流推广
  • 做网站兰州班级优化大师电脑版
  • 软件技术专升本可以报什么专业网站seo关键词设置
  • 网站建设宣传软文范例app营销模式有哪些
  • 建个自己的网站难吗企业做推广有几种方式
  • asp网站转手机站百度智能云
  • 青岛 网站制作公司上海百度竞价托管
  • flash网站代做百度知道首页
  • 厦门网站制作系统亚马逊seo是什么意思
  • 武汉网站设计师培训学校排名优化关键词
  • 四省网站建设今日热点新闻15条
  • 松江营销型网站建设公司开封网站快速排名优化
  • 云南网站建设一度科技公司短链接生成
  • 武汉经济开发区汉南区教育云网站网络营销策划方案
  • 长沙县营销型网站建设选哪家互联网销售是做什么的
  • 腾讯企业邮箱怎么开通注册武汉网站建设优化
  • 江苏省建设厅网站公示怎样去推广自己的网店
  • 高端网站开发费用百度知道登录
  • 网上做兼职的网站有哪些工作北京建公司网站价格
  • 常州有哪些做阿里巴巴网站的想要网站推广页
  • 企业网站开发北京企业宣传ppt
  • 做网站要多少回扣搜索引擎优化包括
  • 网站开发demo百度有几种推广方式
  • 上海专业做网站公贵阳网站建设
  • 烟台h5网站制作品牌推广内容
  • wordpress 经典案例网站移动端优化工具
  • 做流量的网站应该注意什么成人就业技术培训机构
  • 山东mip网站建设搜索引擎免费登录入口
  • 做校园网站的公司免费的建站平台