- MariaDB Cookbook
- Daniel Bartholomew
- 357字
- 2021-07-16 12:19:23
Making backups with mysqldump
The mysqldump
program is included with MariaDB and works well as a simple backup tool.
Getting ready
Create a backup user by following the instructions in the Creating a backup user recipe.
How to do it…
Let's get started by following the ensuing steps:
- To make a complete backup of all the data to a file named
my-backup.sql
, run the following command:mysqldump --user=backupuser -p \ --all-databases > my-backup.sql
- If it completes successfully,
mysqldump
will place a line similar to the following command at the end of the output file:-- Dump completed on <date> <time>
- If a dump fails, an error message will be printed to the screen and the data in the backup file will end right before the error took place. Checking both the error message and the end of the backup file can give us important clues to figure out the failure.
How it works...
The mysqldump
program generates backups in SQL formatted text. These backups can then be restored to the same MariaDB install, to a different MariaDB server, or because they are in SQL format, to a different database altogether.
Depending on the sizes of the databases in our database server, and whether we choose to backup all of the databases or just one or two, the backup file created by mysqldump
could potentially be very large. We need to keep this in mind when using this program.
There's more...
The mysqldump
program has many options. We will discuss some of the most useful ones here.
The --add-drop-database
option causes mysqldump
to add SQL commands to the backup output to drop a given database and then recreate it prior to restoring the data. This helps us to prevent duplicate data from being written to the database.
Similar to the previous option, the --add-drop-table
option causes mysqldump
to add SQL commands to the backup output in order to drop the tables prior to recreating them and inserting data.
- Web程序設(shè)計(jì)及應(yīng)用
- OpenCV 3和Qt5計(jì)算機(jī)視覺應(yīng)用開發(fā)
- 21天學(xué)通C++(第6版)
- Unity Shader入門精要
- 網(wǎng)店設(shè)計(jì)看這本就夠了
- Java軟件開發(fā)基礎(chǔ)
- HTML5+CSS3網(wǎng)站設(shè)計(jì)基礎(chǔ)教程
- iOS編程基礎(chǔ):Swift、Xcode和Cocoa入門指南
- 微信小程序入門指南
- 后臺(tái)開發(fā):核心技術(shù)與應(yīng)用實(shí)踐
- Web程序設(shè)計(jì):ASP.NET(第2版)
- C語言程序設(shè)計(jì)實(shí)踐
- Java設(shè)計(jì)模式深入研究
- 一覽眾山小:ASP.NET Web開發(fā)修行實(shí)錄
- 編寫高質(zhì)量代碼之Java(套裝共2冊(cè))