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.
- 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...
From PyPI:
pip install ibd-parser
From source:
pip install git+https://github.com/likeyiyy/ibd-parser.git
# 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
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)
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
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)
Contributions are welcome! Please feel free to su 7590 bmit 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
This project is licensed under the MIT License - see the LICENSE file for details.
- Based on the InnoDB storage engine documentation
- Inspired by various InnoDB internals research papers and blog posts
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!
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