Lesson 29 / 30

Backup & Restore

Back up and restore a MySQL database with mysqldump and schedule regular backups with cron.

Backing up

mysqldump writes the schema and data as SQL statements to a file.

mysqldump -u root -p shop > shop_backup.sql

Restoring

Feed the dump file back into mysql to recreate the database exactly.

mysql -u root -p shop < shop_backup.sql

Automate it

Schedule mysqldump with cron for regular backups — a single lost server shouldn't mean lost data.

Final quiz 1 of 8

Final quiz

Quick check: Which key uniquely identifies each row?

  • Foreign key
  • Index only
  • Primary key
  • View
Answer

Primary key — A primary key has no duplicates and no NULLs.

Final quiz 2 of 8

Final quiz

Quick check: Which clause filters groups after aggregation?

  • WHERE
  • LIMIT
  • ORDER BY
  • HAVING
Answer

HAVING — WHERE runs before grouping; HAVING runs after.

Final quiz 3 of 8

Final quiz

Quick check: Which join keeps all rows from the left table?

  • LEFT JOIN
  • INNER JOIN
  • CROSS JOIN only
  • UNION
Answer

LEFT JOIN — Unmatched right-side columns become NULL.

Final quiz 4 of 8

Final quiz

Quick check: Which data type is best for money?

  • FLOAT
  • DECIMAL
  • TEXT
  • BOOLEAN
Answer

DECIMAL — DECIMAL stores exact values without rounding errors.

Final quiz 5 of 8

Final quiz

Quick check: What does ROLLBACK do?

  • Commits changes
  • Creates an index
  • Undoes changes since the transaction started
  • Deletes the table
Answer

Undoes changes since the transaction started — It restores the state before START TRANSACTION.

Final quiz 6 of 8

Final quiz

Quick check: What does EXPLAIN type: ALL usually signal?

  • A perfect index use
  • An empty table
  • A syntax error
  • A full table scan
Answer

A full table scan — It often means a useful index is missing.

Final quiz 7 of 8

Final quiz

Quick check: Why avoid using root for an application?

  • It has far more privileges than needed
  • It is slower
  • It cannot connect remotely
  • It lacks SELECT
Answer

It has far more privileges than needed — Least privilege limits the damage of a compromise.

Final quiz 8 of 8

Final quiz

Quick check: Which tool creates a logical backup of a MySQL database?

  • mysqlcheck only
  • mysqldump
  • ls
  • git
Answer

mysqldump — mysqldump writes schema and data as SQL.