How to use mysqldump for full and point-in-time backups

How to use mysqldump for full and point-in-time backups

Mysqldump is used for logical backup in MySQL. Although it is not fast, it is very flexible and has many functions. It is definitely a powerful tool when used flexibly.

First, let's think about a question: why does MySQL need to be backed up? The main reason is data security. For example, if the main database crashes and the data is accidentally deleted, a full backup is very important.

Should full backup be performed from the primary database or the secondary database?

1: From the main library

The main database is more important, but in fact, the backup will not affect the database

mysqldump --host= --user= --password= --single-transaction --master-data=1 --flush-logs --databases >~/db.log

The --single-transaction parameter enables consistent reading without locking the table, which means that data updates are not affected during backup.

it dumps the consistent state of the database at the time when START TRANSACTION was issued without blocking any applications.

Because consistent reading can guarantee the location of the coordinates point, even if the backup time is long, the correct synchronization location point can be obtained.

While a —single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log coordinates)

The --master-data parameter is also very important. The exported statements will contain the CHANGE MASTER TO statement, including the binary file and location point synchronized to the backup statement.

Use this option to dump a master replication server to produce a dump file that can be used to set upanother server as a slave of the master. It causes the dump output to include a CHANGE MASTER TO statement that indicates the binary log coordinates (file name and position) of the dumped server. These are the master server coordinates from which the slave should start replicating after you load the dump file into the slave.

--flush-logs will force the regeneration of a new binary file, which will make recovery easier.

2: From the secondary library

It feels safer to back up from the secondary library.

mysqldump --host=--user= --password= --dump-slave=1 --flush-logs --apply-slave-statements --include-master-host-port --databases >~/db.log;

The --dump-slave and --master-data parameters are very similar:

This option is similar to --master-data except that it is used to dump a replication slave server to produce a dump file that can be used to set up another server as a slave that has the same master as the dumped server. It causes the dump output to include a CHANGE MASTER TO statement that indicates the binary log coordinates (file name and position) of the dumped slave's master. These are the master server coordinates from which the slave should start replicating.

Remember that it gets the bin log coordinates of the primary library (not the backup library)

—dump-slave causes the coordinates from the master to be used rather than those of the dumped server

The dumped statement will include — Position to start replication or point-in-time recovery from.

--apply-slave-statements will automatically include the start and stop slave statements in the dump statement. --include-master-host-port includes the connection information of the master library.

One thing must be remembered, even with the --single-transaction statement, --dump-slave will suspend MySQL synchronization, that is, the data in the backup database lags behind the main database, so the general automated script will remove the backup database first when backing up.

This option causes mysqldump to stop the slave SQL thread before the dump and restart it again after.

3: How to perform point-in-time recovery

I haven't tried it in practice. First, restore based on the most recent full backup, and then import subsequent binlog files (if these files are still there), so it is best to back up the binlog statements in the secondary database as well.

If the data is deleted by mistake, import the binlog statements from the backup point (--flush-logs takes effect) to this morning, or find a safe binlog location to restore it. As for how to skip "dangerous statements", it is more difficult to control.

The above is the details of how to use mysqldump for full and point-in-time backup. For more information about mysqldump for full and point-in-time backup, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • mysqldump parameters you may not know
  • Implementation of MySQL5.7 mysqldump backup and recovery
  • Detailed explanation of the idea of ​​using mysqldump+expect+crontab to implement mysql periodic cold backup in linux
  • Summary of MySql import and export methods using mysqldump
  • Detailed explanation of the use of MySQL mysqldump
  • Docker uses the mysqldump command to back up and export mysql data in the project
  • MySQL data migration using MySQLdump command
  • PHP scheduled backup MySQL and mysqldump syntax parameters detailed
  • Detailed explanation of how to use the mysql backup script mysqldump
  • Detailed explanation of Linux mysqldump exporting database, data, and table structure
  • Detailed discussion on the issue of mysqldump data export
  • Use of MySQL official export tool mysqlpump

<<:  How to reset the root password in Linux mysql-5.6

>>:  Eight ways to implement communication in Vue

Recommend

MYSQL database basics - Join operation principle

Join uses the Nested-Loop Join algorithm. There a...

Use non-root users to execute script operations in docker containers

After the application is containerized, when the ...

Native js to realize bouncing ball

On a whim, I wrote a case study of a small ball b...

CSS3 analysis of the steps for making Douyin LOGO

"Tik Tok" is also very popular and is s...

Based on the special characters in the URL escape encoding

Table of contents Special characters in URLs URL ...

The leftmost matching principle of MySQL database index

Table of contents 1. Joint index description 2. C...

The unreasonable MaxIdleConns of MySQL will cause short connections

1 Background Recently, some performance issues ha...

How to encapsulate the table component of Vue Element

When encapsulating Vue components, I will still u...

CSS border adds four corners implementation code

1.html <div class="loginbody"> &l...

Linux Jenkins configuration salve node implementation process diagram

Preface: Jenkins' Master-Slave distributed ar...

A brief discussion of 3 new features worth noting in TypeScript 3.7

Table of contents Preface Optional Chaining Nulli...

In-depth explanation of the impact of NULL on indexes in MySQL

Preface I have read many blogs and heard many peo...