Detailed explanation of MYSQL log and backup and restore issues

Detailed explanation of MYSQL log and backup and restore issues

This article shares MYSQL logs and backup and restore for your reference. The specific content is as follows

1. Error log

When the database fails and cannot be used, check the log first.

1. Information during server startup and shutdown

2. Error information during server operation

The log storage path can be viewed through the command:

Log file naming format: host_name.err

2. Binary Log

Also known as BINLOG, it records all DDL statements and DML statements, excluding query statements. This log is not only very important, but as a developer I also really like this log. As can be seen from its definition, this log records all events that will change the table structure and table data, so once the data is deleted by mistake or lost due to other reasons, we can restore the data through this log. Don’t you think it’s cool?

Log storage path: in the same directory as the error log

Naming method: The default method is hostname-bin + number

Every time MySQL starts or flushes the log, it generates a new binlog, and the numbering starts from 1 and increases. When a single log reaches a certain size, a new file is generated.

1. Turn on the switch for recording binlog

In the installation directory of myslq, there is a configuration file: my.ini

innodb_buffer_pool_size=107M

# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=54M

# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=10

log-bin=mysql-bin

log-bin indicates that the switch is turned on, and mysql-bin is the prefix of the log name.

2. How to view BINLOG

Because it is a binary file, it cannot be viewed directly like an error log. You need to use the tool provided by MySQL: mysqlbinlog

3. View BINLOG by time

One thing to note when querying by time is that start-datetime is a closed interval, and stop-datetime is an open interval. So if you need to query the whole day's log, you need to define it as:
--start-datetime="2017/07/12 00:00:00" --stop-datetime="2017/07/13 00:00:00": The query time range is 7/12 00:00:00 - 7/12 24:59:59

3. Data backup

Data backup actually uses the tool mysqldump provided by msyql to back up data to a specified file in a specified directory.

1. Back up the specified database or some tables in the database

mysqldump 【option】 db_name 【table_names】

2. Back up one or more specified databases

mysqldump 【option】 --database db_name1 db_name2

3. Back up all databases

mysqldump [option] -all -databases

Export the table structure and table data in the database wd_msg in the database instance with port 3306 to the cd.sql file

The contents of the cd.sql file are as follows;

This file records DML statements and DDL statements, excluding query-related operations. When recovering data, these statements can be executed one by one to complete the data restoration.

4. Data Recovery

We delete the table and re-import the data we just exported:

The following scenario is to restore the wd_msg database in another MySQL instance with port 3307 on the same server.

MySQL backup and restore has different options for different scenarios. This is just one of the concepts introduced here. There will be articles that will introduce it in detail later.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of mysqldump backup and restore and mysqldump import and export statements
  • PHP code to backup/restore MySQL database
  • Recommended MySQL database backup and restore methods
  • Summary of common commands for MySQL database backup and restore
  • Tutorial on using innobackupex and xtrabackup to backup and restore big data in MySQL
  • Detailed explanation of MYSQL backup and restore (PHP implementation)
  • Summary of statements for backing up and restoring MySQL database in command line mode
  • MySQL uses commands to back up and restore the database
  • Where is the MySQL log file? How to modify the MySQL log file location
  • MySQL tracks the SQL statements executed by viewing the trace log

<<:  How to set up scheduled backup tasks in Linux centos

>>:  Detailed explanation of how to stop the Docker container from automatically exiting

Blog    

Recommend

display:grid in CSS3, an introduction to grid layout

1. Grid layout (grid): It divides the web page in...

Axios cancels repeated requests

Table of contents Preface 1. How to cancel a requ...

Web page HTML code explanation: ordered list and unordered list

In this section, we will learn about list element...

How to limit the input box to only input pure numbers in HTML

Limit input box to only pure numbers 1、onkeyup = ...

Use of filter() array filter in JS

Table of contents 1. Introduction 2. Introduction...

How to completely delete and uninstall MySQL in Windows 10

Preface This article introduces a tutorial on how...

Detailed analysis of javascript data proxy and events

Table of contents Data Brokers and Events Review ...

Application of anchor points in HTML

Set Anchor Point <a name="top"><...

Hide HTML elements through display or visibility

Sometimes we need to control whether HTML elements...

What are the core modules of node.js

Table of contents Global Object Global objects an...

Summary of pitfalls encountered in installing mysql and mysqlclient on centos7

1. Add MySQL Yum repository MySQL official websit...

JavaScript to achieve JD.com flash sale effect

This article shares the specific code of JavaScri...