MySQL full backup and quick recovery methods

MySQL full backup and quick recovery methods

A simple MySQL full backup script that backs up the data for the last 15 days.

Backup

#Back up the mysql database every day (save the data script for the last 15 days)

DATE=$(date +%Y%m%d)

/home/cuixiaohuan/lamp/mysql5/bin/mysqldump -uuser -ppassword need_db > /home/cuixiaohuan/bak_sql/mysql_dbxx_$DATE.sql;

find /home/cuixiaohuan/bak_sql/ -mtime +15 -name '*.sql' -exec rm -rf {} \;

recover

mysql data import

drop databases need_db;

create databases need_db;

Import data: Encoding must be set for recovery

./mysql -uroot -p --default-character-set=utf8 need_db < xx.sql

Knowledge point expansion:

Backup and restore using mysqldump

1. Backup principle

The backup principle of mysqldump is relatively simple. First, find out the table structure that needs to be backed up and generate a create statement in a text file; then convert all data records in the table into an insert statement; these statements can be used to create a table and insert data.

2. Back up a database

Basic syntax:

>>> mysqldump -u username -p dbname table1 table2 ... > BackupName.sql

Example description:

mysqldump -u root -p test person > /tmp/backup.sql

3. Back up multiple databases

Basic syntax:

mysqldump -u username -p --databases dbname2 dbname2 > BackupName.sql

Example description:

mysqldump -u root -p --databases test mysql > /tmp/backup.sql

4. Back up all databases

Basic syntax:

mysqldump -u username -p -all-databases > BackupName.sql

Example description:

mysqldump -u -root -p -all-databases > /tmp/all.sql

5. Data Recovery

Basic syntax:

mysql -u root -p [dbname] < backup.sql

Example description:

mysql -u root -p < /tmp/backup.sql

The above is the detailed content of the method of MySQL full backup and quick recovery. For more information about MySQL simple full backup and quick recovery methods, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed steps for configuring mysql8.0.20 with binlog2sql and simple backup and recovery
  • A brief analysis of MySQL backup and recovery
  • Detailed explanation of mysql backup and recovery
  • MySQL database backup and recovery implementation code
  • Analysis of MySQL data backup and recovery implementation methods
  • Shell script to implement mysql scheduled backup, deletion and recovery functions
  • How to restore a database and a table from a MySQL full database backup
  • How to restore single table data using MySQL full database backup data
  • MySQL incremental backup and breakpoint recovery script example
  • C# implements MySQL command line backup and recovery
  • MySQL backup and recovery design ideas

<<:  Detailed explanation of the differences between var, let and const in JavaScript es6

>>:  Detailed tutorial on how to connect to a remote server Docker to deploy a Spring Boot project in IDEA

Recommend

Five things a good user experience designer should do well (picture and text)

This article is translated from the blog Usability...

Detailed explanation of Linux DMA interface knowledge points

1. Two types of DMA mapping 1.1. Consistent DMA m...

Html comments Symbols for marking text comments in Html

HTML comments, we often need to make some HTML co...

Records of using ssh commands on Windows 8

1. Open the virtual machine and git bash window a...

WeChat Mini Program QR Code Generation Tool weapp-qrcode Detailed Explanation

WeChat Mini Program - QR Code Generator Download:...

MySQL database operations (create, select, delete)

MySQL Create Database After logging into the MySQ...

Summary of Git commit log modification methods

Case 1: Last submission and no push Execute the f...

JQuery implements hiding and displaying animation effects

This article shares the specific code of JQuery t...

An article teaches you how to use Vue's watch listener

Table of contents Listener watch Format Set up th...

Installation process of MySQL5.7.22 on Mac

1. Use the installation package to install MySQL ...

A brief discussion on the correct approach to MySQL table space recovery

Table of contents Preliminary Notes Problem Repro...