Backups with mysqldump

mysqldump is MySQL's built-in backup tool — it reads a database and writes out the plain SQL needed to recreate it from scratch, table structure and data included.

Backing up a single database

shell terminal
$ mysqldump -u root -p shop > shop_backup.sql
Output
Enter password: 
$

No visible output on success — mysqldump writes the entire backup to standard output, which the > redirects into shop_backup.sql. Opening that file shows plain CREATE TABLE and INSERT statements, exactly what you'd need to type by hand to rebuild the database.

Restoring from a backup

shell terminal
$ mysql -u root -p shop < shop_backup.sql
Output
Enter password: 
$

Note the direction of the redirect flips: mysqldump writes out with >, restoring reads in with <. The target database (shop here) needs to already exist before you restore into it.

Backing up everything on the server

shell terminal
$ mysqldump -u root -p --all-databases > full_backup.sql
Output
Enter password: 
$
Course complete: that covers the MySQL course — connecting with the CLI, MySQL's own data types and their limits, creating databases and tables with AUTO_INCREMENT, choosing InnoDB over MyISAM, adding indexes and reading EXPLAIN, scoping user privileges instead of running everything as root, MySQL's built-in functions, stored procedures, native JSON columns, and backing up with mysqldump. Together with the site's general SQL course, you now have what you need to run and administer a real MySQL database, not just query one.
--single-transaction matters on a busy database: a plain mysqldump against InnoDB tables that are actively being written to can capture some tables mid-change, producing a backup that's inconsistent with itself. Adding --single-transaction takes a consistent snapshot at the moment the dump starts, without locking the tables — for InnoDB, it's the flag you almost always want for a backup that matters.