RESTORE TABLE - MySQL


Overview

The RESTORE TABLE command in MySQL is used to restore the data and structure of a database table from a previously created backup. It allows users to recover lost or corrupted data, revert to an earlier state of the table, or migrate data between different databases.

Syntax

RESTORE TABLE `table_name` FROM `filename` [OPTIONS]

Options/Flags

| Option | Description | Default |
|—|—|—|
| HANDLER | Specifies the storage engine to be used for the restored table. | DEFAULT |
| IGNORE CHECKS | Skips checking foreign key constraints during the restore. | OFF |
| CASCADE | Automatically restores dependent objects, such as foreign keys and indexes. | OFF |
| SKIP EXTENDED INSERT | Omits extended inserts for restoring data. | OFF |
| SKIP VALIDATE | Skips table validation during the restore, which can speed up the process. | OFF |

Examples

Simple Restoration:

RESTORE TABLE customers FROM '/backup/customers.sql';

Restoration with Options:

RESTORE TABLE orders
FROM '/backup/orders.sql'
HANDLER InnoDB
IGNORE CHECKS
CASCADE
SKIP VALIDATE;

Restoration of Multiple Tables:

RESTORE TABLE customers, orders FROM '/backup/all_tables.sql';

Common Issues

  • Missing Backup File: Ensure that the specified backup file exists and is accessible.
  • Wrong Table Name: Double-check that the table_name specified matches the table you want to restore.
  • Permissions Denied: Verify that the user has sufficient privileges to restore the table.
  • Table Already Exists: If the restored table already exists, use the REPLACE option to overwrite it.

Integration

The RESTORE TABLE command can be combined with other MySQL commands, such as:

  • mysqldump: To create backups for restoration.
  • CHANGE MASTER TO: To restore data into a replica server.
  • PERCONA XTRADB BACKUP: For point-in-time recovery.
  • BACKUP TABLE
  • mysqldump
  • pt-table-checksum