Rechercher dans le manuel MySQL
7.5.1 Point-in-Time Recovery Using Binary Log
This section explains the general idea of using the binary log to perform a point-in-time-recovery. The next section, Section 7.5.2, “Point-in-Time Recovery Using Event Positions”, explains the operation in details with an example.
Many of the examples in this and the next section use the mysql
client to process binary log output produced by mysqlbinlog. If your
binary log contains \0
(null) characters, that output cannot be parsed
by mysql unless you invoke it with the --binary-mode
option.
The source of information for point-in-time recovery is the set of binary log files generated subsequent to the full backup operation. Therefore, to allow a server to be restored to a point-in-time, binary logging must be enabled on it, which is the default setting for MySQL 8.0 (see Section 5.4.4, “The Binary Log”).
To restore data from the binary log, you must know the name and location of the current
binary log files. By default, the server creates binary log files in the data directory, but
a path name can be specified with the --log-bin
option to
place the files in a different location. To see a listing of all binary log files, use this
statement:
To determine the name of the current binary log file, issue the following statement:
The mysqlbinlog utility converts the events in the binary log files from binary format to text so that they can be viewed or applied. mysqlbinlog has options for selecting sections of the binary log based on event times or position of events within the log. See Section 4.6.8, “mysqlbinlog — Utility for Processing Binary Log Files”.
Applying events from the binary log causes the data modifications they represent to be reexecuted. This enables recovery of data changes for a given span of time. To apply events from the binary log, process mysqlbinlog output using the mysql client:
shell> mysqlbinlog binlog_files | mysql -u root -p
If binary log files have been encrypted, which can be done from MySQL 8.0.14 onwards,
mysqlbinlog cannot read them directly as in the above example, but can
read them from the server using the --read-from-remote-server
(-R
) option. For example:
shell> mysqlbinlog --read-from-remote-server --host=host_name --port=3306 --user=root --password --ssl-mode=required binlog_files | mysql -u root -p
Here, the option --ssl-mode=required
has been used to ensure that
the data from the binary log files is protected in transit, because it is sent to
mysqlbinlog in an unencrypted format.
Viewing log contents can be useful when you need to determine event times or positions to select partial log contents prior to executing events. To view events from the log, send mysqlbinlog output into a paging program:
shell> mysqlbinlog binlog_files | more
Alternatively, save the output in a file and view the file in a text editor:
shell> mysqlbinlog binlog_files > tmpfile
shell> ... edit tmpfile ...
Saving the output in a file is useful as a preliminary to executing the log contents
with certain events removed, such as an accidental DROP
TABLE
. You can delete from the file any statements not to be executed before
executing its contents. After editing the file, apply the contents as follows:
shell> mysql -u root -p < tmpfile
If you have more than one binary log to apply on the MySQL server, the safe method is to process them all using a single connection to the server. Here is an example that demonstrates what may be unsafe:
shell> mysqlbinlog binlog.000001 | mysql -u root -p # DANGER!!
shell> mysqlbinlog binlog.000002 | mysql -u root -p # DANGER!!
Processing binary logs this way using different connections to the server causes
problems if the first log file contains a CREATE TEMPORARY TABLE
statement and the second log contains a statement that
uses the temporary table. When the first mysql process terminates, the
server drops the temporary table. When the second mysql process attempts
to use the table, the server reports “unknown table.”
To avoid problems like this, use a single connection to apply the contents of all binary log files that you want to process. Here is one way to do so:
shell> mysqlbinlog binlog.000001 binlog.000002 | mysql -u root -p
Another approach is to write the whole log to a single file and then process the file:
shell> mysqlbinlog binlog.000001 > /tmp/statements.sql
shell> mysqlbinlog binlog.000002 >> /tmp/statements.sql
shell> mysql -u root -p -e "source /tmp/statements.sql"
When writing to a dump file while reading back from a binary log containing GTIDs (see
Section 17.1.3, “Replication with Global Transaction Identifiers”), use the --skip-gtids
option with mysqlbinlog, like this:
shell> mysqlbinlog --skip-gtids binlog.000001 > /tmp/dump.sql
shell> mysqlbinlog --skip-gtids binlog.000002 >> /tmp/dump.sql
shell> mysql -u root -p -e "source /tmp/dump.sql"
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-point-in-time-recovery-binlog.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.