|
| 1 | +# ibd2mysql |
| 2 | + |
| 3 | +[](https://packagist.org/packages/j0celyn/ibd2mysql) |
| 4 | +[](https://packagist.org/packages/j0celyn/ibd2mysql) |
| 5 | +[](https://packagist.org/packages/j0celyn/ibd2mysql) |
| 6 | + |
| 7 | +## Description |
| 8 | + |
| 9 | +MySQL provides the configuration flag [innodb_force_recovery](https://dev.mysql.com/doc/refman/8.0/en/forcing-innodb-recovery.html) to help you fix several kinds of errors. |
| 10 | +You should first check if it can help you fix your problems. |
| 11 | + |
| 12 | +**ibd2mysql** is a tool to try to recover InnoDB tables under the following conditions: |
| 13 | +- MySQL Server v8.0.0 or newer |
| 14 | +- your tables are using the InnoDB engine |
| 15 | +- [innodb_file_per_table](https://dev.mysql.com/doc/refman/8.0/en/innodb-parameters.html#sysvar_innodb_file_per_table) was enabled in the MySQL Server configuration **before** you ran into problems |
| 16 | + (in the MySQL data directory, you should see at least one IBD file for each of your tables) |
| 17 | +- the MySQL data dictionary is corrupted or missing (the server no longer knows what tables each database contains, despite the IBD files still being there) |
| 18 | + |
| 19 | + |
| 20 | +## Requirements |
| 21 | + |
| 22 | +- PHP 8 |
| 23 | +- MySQL 8 |
| 24 | + |
| 25 | +## Installation |
| 26 | + |
| 27 | +#### Install via composer: |
| 28 | + composer require j0celyn/ibd2mysql |
| 29 | + |
| 30 | +## Setup |
| 31 | + |
| 32 | +⚠️ The IBD file format evolving with each MySQL version, it is highly recommended to run this script using the version of the MySQL Server that created the IBD files you are trying to recover. |
| 33 | +If using a different MySQL version, you will probably still be able to extract the SDI information and create the SQL files. However the **--repair** option is likely to fail with fatal errors when importing your IBD files into the MySQL Server. |
| 34 | + |
| 35 | +Rename `config-empty.php` to `config.php`, then edit its values: |
| 36 | +- **DB_HOST**: your MySQL server host |
| 37 | +- **DB_PORT**: your MySQL server port |
| 38 | +- **DB_USER**: your MySQL server user |
| 39 | +- **DB_PASSWORD**: your MySQL server password |
| 40 | +- **MYSQL_DATA_DIR**: full path to the MySQL data directory of your server |
| 41 | +- **IBD2SDI_PATH**: full path to the directory that holds the [ibd2sdi](https://dev.mysql.com/doc/refman/8.0/en/ibd2sdi.html) program. It was probably installed together with your MySQL server |
| 42 | +- **BACKUP_DIR**: full path to the directory of backup IBD files (the IBD files that contain your MySQL data) |
| 43 | +- **OUTPUT_DIR**: full path to the directory where this script will create SDI and SQL files |
| 44 | + |
| 45 | +### Usage |
| 46 | +Here are the available options: |
| 47 | +- **--sdi**: extracts SDI information from IBD files. **Note: Existing SDI files will be overwritten.** |
| 48 | +- **--sql**: creates MySQL files from SDI files. **Note: Existing SQL files will be overwritten.** |
| 49 | +- **--repair**: for each table: |
| 50 | + - runs the MySQL files to create the table |
| 51 | + - moves IBD file(s) to replace the empty tablespace with your saved tablespace |
| 52 | + - if needed, optimizes the table to fix some issues |
| 53 | + |
| 54 | + **Note: Existing MySQL tables will not be altered.** |
| 55 | + |
| 56 | +When the script is called with more than one option, they will always run in the same order: **sdi sql repair** |
| 57 | + |
| 58 | +To run the script, use one or more options. |
| 59 | + |
| 60 | +#### Examples: |
| 61 | + |
| 62 | + php vendor/j0celyn/ibd2mysql/convert.php --sdi |
| 63 | + php vendor/j0celyn/ibd2mysql/convert.php --sdi --sql |
0 commit comments