A Python tool for parsing and analyzing InnoDB .ibd files
Project description
InnoDB IBD File Parser
A Python tool for parsing and analyzing InnoDB .ibd files. This tool helps database administrators and developers understand the internal structure of InnoDB tablespace files.
Features
- Parse InnoDB page headers
- Analyze index pages
- Extract record contents
- Support for various page types:
- Index pages (B-tree nodes)
- File space header
- XDES (Extent descriptor)
- BLOB pages
- And more...
Installation
From PyPI:
pip install ibd-parser
From source:
pip install git+https://github.com/likeyiyy/ibd-parser.git
Usage
Command Line Interface
# Show page header
ibd-parser -f /path/to/table.ibd header --page 4
# Dump records from an index page
ibd-parser -f /path/to/table.ibd records --page 4
Python API
from ibd_parser import IBDFileParser
# Initialize parser with your .ibd file
parser = IBDFileParser("/path/to/your/table.ibd")
# Analyze a specific page
page_info = parser.analyze_page(page_no=4)
# Access page information
print(f"Page Type: {page_info['header'].page_type}")
if 'index_header' in page_info:
print(f"Number of records: {page_info['index_header'].n_recs}")
# Get records from an index page
records = parser.get_records(page_no=4)
for record in records:
print(record.data)
# Hex dump of a page
parser.hex_dump(page_no=4, length=128)
Project Structure
ibd_parser/
├── ibd_parser/
│ ├── __init__.py
│ ├── constants.py # Constants and enums
│ ├── page.py # Page structure definitions
│ ├── record.py # Record parsing
│ ├── parser.py # Main parser implementation
│ ├── cli.py # Command line interface
│ └── utils.py # Utility functions
├── tests/
├── README.md
└── pyproject.toml # Project metadata and dependencies
Page Structure
An InnoDB page (default 16KB) consists of:
- File Header (38 bytes)
- Page Header (56 bytes)
- Infimum/Supremum Records
- User Records
- Free Space
- Page Directory
- File Trailer (8 bytes)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Based on the InnoDB storage engine documentation
- Inspired by various InnoDB internals research papers and blog posts
References
Future Plans
I will continue to enhance this project to make it more practical and valuable. Planned improvements include:
- Support for more page types
- Enhanced record analysis
- Data recovery features
- More comprehensive CLI tools
- Better documentation and examples
Contributions and suggestions are welcome!
Testing and Development
Creating Test Data
The project includes a script to create a test database with various column types:
# Install MySQL Connector
pip install mysql-connector-python
# Set MySQL connection environment variables (if needed)
export MYSQL_USER=your_user
export MYSQL_PASSWORD=your_password
export MYSQL_HOST=localhost
export MYSQL_PORT=3306 # Or your Docker mapped port
# Create test database and table
python examples/create_test_data.py
The test table includes common MySQL data types:
- Integer types (TINYINT, SMALLINT, INT, BIGINT)
- Floating point types (FLOAT, DOUBLE, DECIMAL)
- String types (CHAR, VARCHAR, TEXT)
- Date and Time types (DATE, TIME, DATETIME, TIMESTAMP)
- Other types (BOOLEAN, ENUM, BINARY, BLOB)
After creating the test database, you can find the .ibd file at:
/data/docker/mysql/data/ibd_parser_test/test_table.ibd
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ibd_parser-0.1.5.tar.gz.
File metadata
- Download URL: ibd_parser-0.1.5.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e5c8f78424192e65ef703039672a334d36d93d9675564e7d596999722c964e7
|
|
| MD5 |
065c99cc45d5c91b3e3ecbc9f5d0dfb2
|
|
| BLAKE2b-256 |
86edea2338c5440746a0e51b36d0cf1dc9dc557746a5a29aec7d2b59bcb892b1
|
File details
Details for the file ibd_parser-0.1.5-py3-none-any.whl.
File metadata
- Download URL: ibd_parser-0.1.5-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a770cfaa6eabb400ee36e6f529fd2f5c3d6ef783c694b97f853146c2fa38793
|
|
| MD5 |
e02594512b5d730056b203579280825c
|
|
| BLAKE2b-256 |
7be535b8dabe7b0532cb8f361272b4be9c6908948b837a386cc836a3154aafd9
|