# Backup & Restore — MySQL

Source: https://www.geekswithgeeks.com/en/mysql/sql-backup-restore

> Save and reload a database with mysqldump.

## Backing up

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

```bash
mysqldump -u root -p shop > shop_backup.sql
```

## Restoring

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

```bash
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.
