MariaDB Backup and Restore: Verify a SQL Dump on a Separate Database
Use mariadb-dump to save MariaDB table definitions and data as SQL. Restore the file with the mariadb client on a separate test target and compare the restored data with a baseline from the backup time.
Prepare the tools and choose the backup scope
Run the setup SQL on a MariaDB instance isolated from production. Check that both client tools are on your PATH with the version commands. Change the port and lab_user in the commands to match the lab, and enter your password at the --password prompt.
mariadb-dump --version
mariadb --version
CREATE DATABASE backup_source CHARACTER SET utf8mb4;
USE backup_source;
CREATE TABLE lab_orders (
id INT PRIMARY KEY,
order_code VARCHAR(20) NOT NULL,
quantity INT NOT NULL
) ENGINE=InnoDB;
INSERT INTO lab_orders VALUES (1, 'A-001', 4), (2, 'A-002', 7);
Use a lab account that can create the test databases and table, write the sample rows, and read them back. If backup_source already exists, choose a new name or a separate lab server. The MariaDB backup overview also describes physical backups of data files. Consider physical backups and binary logs when restore time or recovery to a specific point matters.
Back up one database to a SQL file
In a restricted working directory, choose a new file named backup-lab.sql. The command works in Bash and PowerShell when the client is on PATH. With --result-file, mariadb-dump writes the file directly.
mariadb-dump --host=127.0.0.1 --port=3306 --user=lab_user --password --single-transaction --quick --skip-add-drop-table --result-file=backup-lab.sql backup_source
--single-transaction gives InnoDB a consistent snapshot and --quick reads rows sequentially. Avoid schema changes during the dump. MyISAM and MEMORY lack the same snapshot guarantee. --skip-add-drop-table omits the generated drop-table statements in this lab. The output path can be overwritten even when the dump fails. Use a new filename and check for exit code 0 with $? in Bash or $LASTEXITCODE in PowerShell.
Back up multiple databases or a whole server
These are command patterns for wider backup scopes. Replace the example database names app_db and analytics_db. Check privileges for the tables, views, triggers, routines and events you need. Triggers are included by default, while routines and events have explicit options.
mariadb-dump --host=127.0.0.1 --port=3306 --user=lab_user --password --single-transaction --quick --routines --events --triggers --hex-blob --result-file=two-databases-new.sql --databases app_db analytics_db
mariadb-dump --host=127.0.0.1 --port=3306 --user=lab_user --password --single-transaction --quick --routines --events --triggers --hex-blob --result-file=all-databases-new.sql --all-databases
Dumps made with --databases or --all-databases can contain CREATE DATABASE and USE for the original names. Choosing a different default database in the client does not override those statements. First restore such dumps on an empty, isolated server using the original names. A server-wide dump can include system tables, so verify version compatibility. Back up server configuration and binary logs separately.
Restore into an empty test database
Review the lab SQL file in your current directory before loading it. Look for USE, fully qualified references to the source database, or unexpected administrative statements. Create a new database named backup_restore_check and choose a fresh name if it already exists. The mariadb command-line client reads the file with SOURCE, so the import works without Bash input redirection in PowerShell.
mariadb --host=127.0.0.1 --port=3306 --user=lab_user --password --execute="CREATE DATABASE backup_restore_check CHARACTER SET utf8mb4"
mariadb --host=127.0.0.1 --port=3306 --user=lab_user --password --abort-source-on-error backup_restore_check --execute="SOURCE backup-lab.sql"
Check the exit status of each command. SOURCE reads the file on the machine running the client. If an older client rejects the sandbox command in a newer dump, use a compatible MariaDB client. A failed import can leave a partially restored database. Fix the cause before retrying against a fresh, empty target.
Verify rows, objects, and recovery time
Compare this SQL output from the restored database with your source baseline. The practice table should contain exactly (1, A-001, 4) and (2, A-002, 7). The last query lists the table and view objects in the restored database.
SELECT id, order_code, quantity
FROM lab_orders
ORDER BY id;
SELECT TABLE_NAME, TABLE_TYPE
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE()
ORDER BY TABLE_NAME;
For a real backup, compare row counts and known values, including totals, text, NULLs and binary samples. Inspect triggers, routines and events. Test views and routines, and confirm event scheduler settings and DEFINER accounts and permissions. A hash detects changes to a stored copy. A timed test restore tells you whether the backup meets recovery needs. Restrict access to the file and keep a copy in separate storage.




