A database dump is a copy of all the data, structure, and settings of a database saved as a file. This file contains all the tables, records, indexes, and other elements. It allows for restoring the database to its original state if needed.
A dump can be used to transfer data between different servers or for development and testing, where having an exact copy of the working database is important.
There are 3 main ways to create a database dump — we will discuss each of them in detail.
Important: Before exporting, ensure that the connection encoding is set to UTF-8 to avoid encoding issues when transferring data.
This method is suitable for more experienced users who are comfortable working in the Terminal or in cases where the hosting control panel or phpMyAdmin is unavailable.
To create a backup, enter the following command in the console:
mysqldump -u[username] -p[password] [database_name] > dump.sql
Let's break it down:
If you encounter encoding issues (e.g., question marks instead of text), add a parameter to use UTF-8 encoding:
mysqldump --default-character-set=utf8 -u[username] -p[password] [database_name] > dump.sql