Applications and operations
Back up and restore MySQL
Create a consistent InnoDB logical dump, restore it into a clean database, and verify both schema and application data.
8 minute lesson
~~~
Create a logical dump of the InnoDB database:
mysqldump -u root -p \
--single-transaction \
--routines --events --triggers \
notes_app > notes_app.sql
--single-transaction gives a consistent snapshot for transactional InnoDB tables. It does not protect nontransactional tables, and schema changes must not run during the dump. A database dump also does not include MySQL accounts and their grants.
Restore into a clean database, never over the original:
mysql -u root -p -e "CREATE DATABASE notes_restore CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci"
mysql -u root -p notes_restore < notes_app.sql
Verify the restored schema and data:
mysql -u root -p notes_restore -e "SHOW TABLES; SELECT COUNT(*) AS notes FROM notes; CHECK TABLE notes, tags, note_tags;"
Start a non-production application against notes_restore too. A successful dump command alone does not prove recovery works.
Lesson completed