Recover from Corrupted Instance

When a MySQL instance cannot open but the data directory is still available, PDU can directly read those files to export data without starting the database service.

I. Initialization

Fill in MYSQL_DATADIR in pdu.ini, i.e., the database directory. Launch PDU in a result directory outside the sources; the launch directory is fixed as the working and output location for the run.

MYSQL_DATADIR=/recovery-input/mysql/data
BINLOG=/recovery-input/mysql/binlog
RESMODE=tx
RESTYPE=delete

Enter the pdu directory and execute b; to complete initialization. Version 5.7 uses FRM/system dictionaries; version 8.0 uses SDI and physical dictionaries to identify tables.

./pdu

b;

II. Enter the Specified Database and Export Table Definitions

2.1 View Current Databases

Use \l; to view selectable databases. After initialization, also review READY and UNAVAILABLE counts in the table inventory.

\l;

2.2 Enter Database and Export Table Definitions

Use use database_name; to select and enter the corresponding database. Use \dt; to view tables and unload ddl database_name; to export table definitions.

use appdb;
\dt;
\d orders;
unload ddl appdb;

III. Export Data Under a Specified Database

Use unload tab table_name; to export one table, or unload db database_name; to export the database. Database export checks all selected tables first; unavailable tables prevent successful database publication.

unload tab orders;

# Or export the database:
unload db appdb;

3.1 How to Use Exported Data

3.1.1 Components of Exported Data

PDU uses its current directory at startup for tasks and output. Exported SQL files are written directly there, and internal task records are stored in .pdu-work. Export table definitions separately with unload ddl. Recovery commands generate SQL without writing to the target database. The records in .pdu-work retain the program's success and failure counts, original errors and checkpoints.

3.1.2 Paths of Exported Data

Exported SQL is written directly to PDU's launch directory. Internal tasks are stored in .pdu-work beneath it. Use the paths reported by PDU; existing output is not overwritten.

After export, record the native success and failure counts and original errors reported by PDU, and retain the checkpoint. Resume uses native records and file metadata such as existence and size without rereading exported data.

3.1.3 Usage of Exported Data

In an isolated target database, create tables with matching DDL before importing data SQL. Replace the example filenames below with actual exported paths.

mysql -h target-host -u recovery_user -p appdb < ./appdb-ddl.sql
mysql -h target-host -u recovery_user -p appdb < ./orders.sql
MySQL 文档