Backing up and restoring a MySQL database

This recipe shows you how to back up your MySQL databases using mysqldump. The utility connects to the MySQL server, queries the structure of the database and its data, and outputs the data in the form of SQL statements. The backup can then be used to restore the database or populate a new database with the data.

Getting ready

This recipe requires a running MySQL server and access to either MySQL's root user or another user with the necessary privileges to perform the backup.

How to do it...

Follow these steps to make a backup of a MySQL database:

  1. Connect to the MySQL database you want to back up:
    mysql -u root -p packt
    
  2. Execute a FLUSH TABLES statement to set the database's tables read-only:
    FLUSH TABLES WITH ...

Get CentOS 7 Server Deployment Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.