A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mariadb.com/docs/server/mariadb-quickstart-guides/mariadb-restore-guide below:

Restoring Data from Dump Files Guide

Restoring Data from Dump Files Guide | MariaDB Documentation
  1. Quickstart Guides
Restoring Data from Dump Files Guide

Data Restoration Guide

This guide explains how to restore your MariaDB data from backup files created with mariadb-dump. Learn the basic restoration process using the mariadb client and a specific technique for selectively restoring a single table while minimizing data loss on other tables.

It's important to understand that mariadb-dump is used for creating backup (dump) files, while the mariadb client utility is used for restoring data from these files. The dump file contains SQL statements that, when executed, recreate the database structure and/or data.

Basic Restoration Process

To restore a dump file, you direct the mariadb client to execute the SQL statements contained within the file.

mariadb --user your_username --password < /path/to/your/backupfile.sql
Important Considerations Before Restoring

Always ensure you understand the contents of the dump file and the potential impact before initiating a restore, especially on a production system. Consider testing the restore on a non-production environment first if possible.

Restoring a Single Table Selectively

If only one table has been lost or corrupted and your backup file contains an entire database (or multiple tables), a full restore might overwrite recent, valid data in other tables. Here’s a method to restore only a specific table using a temporary user with restricted privileges:

  1. Create a Temporary User: Create a MariaDB user specifically for this restore operation.

  2. Grant Limited Privileges:

    Example SQL to create a temporary user and grant permissions (replace placeholders):

    -- Connect to MariaDB as an administrative user (e.g., root)
    CREATE USER 'admin_restore_temp'@'localhost' IDENTIFIED BY 'its_very_secure_pwd';
    
    -- Grant general SELECT on the database (might be needed if dump file structure requires it)
    -- Or, if not needed, ensure the user can at least USE the database.
    GRANT SELECT ON your_database_name.* TO 'admin_restore_temp'@'localhost';
    
    -- Grant full privileges ONLY on the table to be restored
    GRANT ALL PRIVILEGES ON your_database_name.table_to_restore TO 'admin_restore_temp'@'localhost';
    
    FLUSH PRIVILEGES;
  3. Restore Using the Temporary User and --force:

    Use the mariadb client with the temporary user and the --force option. The --force option tells MariaDB to continue executing statements in the dump file even if some SQL errors occur. Errors will occur for operations on tables where admin_restore_temp lacks permissions, but operations on table_to_restore (where permissions were granted) should succeed.

    Bash

    mariadb --user admin_restore_temp --password --force your_database_name < /path/to/your/fulldumpfile.sql

    You will be prompted for the password of admin_restore_temp.

  4. Verify Restoration: Check that table_to_restore has been correctly restored.

  5. Clean Up: Drop the temporary user once the restoration is confirmed:

    DROP USER 'admin_restore_temp'@'localhost';

This method helps to isolate the restore operation to the intended table, protecting other data from being inadvertently reverted to an older state.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4