- 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.
- 數(shù)據(jù)庫(kù)系統(tǒng)原理及MySQL應(yīng)用教程(第2版)
- Git Version Control Cookbook
- 構(gòu)建移動(dòng)網(wǎng)站與APP:HTML 5移動(dòng)開(kāi)發(fā)入門(mén)與實(shí)戰(zhàn)(跨平臺(tái)移動(dòng)開(kāi)發(fā)叢書(shū))
- HTML5+CSS3網(wǎng)頁(yè)設(shè)計(jì)
- 青少年P(guān)ython編程入門(mén)
- Learning Concurrent Programming in Scala
- Python High Performance Programming
- Learning Continuous Integration with TeamCity
- Access 2010中文版項(xiàng)目教程
- Android驅(qū)動(dòng)開(kāi)發(fā)權(quán)威指南
- Flowable流程引擎實(shí)戰(zhàn)
- HoloLens與混合現(xiàn)實(shí)開(kāi)發(fā)
- 精通MySQL 8(視頻教學(xué)版)
- 硬件產(chǎn)品設(shè)計(jì)與開(kāi)發(fā):從原型到交付
- 交互式程序設(shè)計(jì)(第2版)