How to take backup of MySQL database

We will make use of the mysqldump utility to take the backup of a MySQL database.

Run the following command to take the backup of a MySQL database:

mysqldump -u root -p <database_name> > /<location_where_you_want_to_take_the backup>/<database_name>.sql

Example:

mysqldump -u root -p my_wordpress_site > /Users/MySQLDumps/my_wordpress_site_dump.sql

In the above example, my_wordpress_site is the database name for which you want to take the backup. When the above command is executed the backup of my_wordpress_site database will be taken at /Users/MySQLDumps/my_wordpress_site_dump.sql location. Make sure the directory is present at /Users/MySQLDumps/ location before running that command.

If you are getting the zsh: command not found: mysqldump while rtunning the above command then you can refer the following reference: zsh: command not found: mysqldump

The backup file taken by the above command will look like this:

-- MySQL dump 10.13  Distrib 8.0.27, for macos11 (x86_64)
--
-- Host: localhost    Database: my_wordpress_site
-- ------------------------------------------------------
-- Server version	8.0.27

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `wp_commentmeta`
--

DROP TABLE IF EXISTS `wp_commentmeta`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `wp_commentmeta` (
  `meta_id` bigint unsigned NOT NULL AUTO_INCREMENT,