py_innodb_page_info分析ibd文件信息
py_innodb_page_info工具是《MySQL技术内幕 InnoDB存储引擎》作者用来分析Mysql表空间的各页的类型和数据,此工具采用python编写,github地址如下
https://github.com/happieme/py_innodb_page_info
通过README.md文件我们可以知道安装此工具前需要先安装python环境,步骤如下
初始准备
### 将项目从git上面下载到本地并且上传到文件夹中,并且解压
unzip py_innodb_page_info-master.zip
### 修改文件夹名字为py_innodb_page_info,可以不改,本文已经修改
mv py_innodb_page_info-master py_innodb_page_info
### 进入py_innodb_page_info文件夹创建ibds文件夹
mkdir ibds
### 准备ibd文件放入ibds文件夹中,测试所用文件为student.ibd
安装Python环境
#### 一定一定注意,需要安装python2的环境而不是python3的环境,因为这个工具基于python2开发,在语法上
### 和python3有不兼容的地方,后面执行脚本可能报错,如下
# Traceback (most recent call last):
# File "py_innodb_page_info.py", line 3, in <module>
# import mylib
# File "/usr/local/py_innodb_page_info/mylib.py", line 19
# print 'Usage: python py_innodb_page_info.py [OPTIONS] tablespace_file'
# SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Usage: python py_innodb_page_info.py [OPTIONS] tablespace_file')
### 所以这里一定要选python2,有的系统安装了apt就可以用apt,本文测试采用apt-get
apt-get install python2
### 安装完环境可以验证下
python2 -v
验证
#### 验证环境是否安装正确
[root@test py_innodb_page_info]# python2 py_innodb_page_info.py ibds/student.ibd
Total number of page: 6:
Freshly Allocated Page: 2
Insert Buffer Bitmap: 1
File Space Header: 1
B-tree Node: 1
File Segment inode: 1
分析ibd文件具体表结构,案例中是student.idb文件
### 查看student.idb表的具体表空间
[root@test py_innodb_page_info]# python2 py_innodb_page_info.py ibds/student.ibd -v
page offset 00000000, page type <File Space Header>
page offset 00000001, page type <Insert Buffer Bitmap>
page offset 00000002, page type <File Segment inode>
page offset 00000003, page type <B-tree Node>, page level <0000>
page offset 00000000, page type <Freshly Allocated Page>
page offset 00000000, page type <Freshly Allocated Page>
Total number of page: 6:
Freshly Allocated Page: 2
Insert Buffer Bitmap: 1
File Space Header: 1
B-tree Node: 1
File Segment inode: 1
ibd文件位置
文件中的student.ibd文件就是来源于Mysql中的表结构,文件路径位于默认配置文件my.cnf配置的datadir路径
例如在mysql中存在一个test数据库,里面包含一个student表
### 切换到test数据库
mysql> use test;
### 查询test数据库的所有表格
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| grade |
| student |
| tb_student |
| tb_student2 |
| test |
| test1 |
+----------------+
在datadir配置的路径下展示如下
进入数据库名字的文件夹后,就能看到数据库表相关文件
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)