The simplest MySQL data backup and restore tutorial in history (Part 1) (Part 35)

The simplest MySQL data backup and restore tutorial in history (Part 1) (Part 35)

The first article on data backup and restoration is shared with you. The specific content is as follows

Basic concepts:

Backup, save another copy of the current data or records;

Restore: restore the data to the state at the time of backup.

Why do we need to back up and restore data?

Prevent data loss;
Protect data records.

There are many ways to back up and restore data, which can be divided into: data table backup, single table data backup, SQL backup and incremental backup.

Data table backup

To back up the data table, we do not need to use SQL. We can directly enter the database folder to copy the corresponding table structure and data. When we need to restore the data, we can simply put the backup (copy) content back.

However, there are prerequisites for backing up data tables because different storage engines are different.

For storage engines, MySQL mainly uses two types: InnoDB and Myisam, both of which are free. Here, we can also popularize the knowledge of storage engines:

Among them, the data storage methods of Myisam and InnoDB are also different:

Myisam: tables, data and indexes are all stored separately;
InnoDB: Only the table structure is present, and all data is stored in ibd files.

Execute the following SQL statement to test the data storage method of Myisam:

-- Create a Myisam table create table my_myisam(
 id int
)charset utf8 engine = myisam;

-- Display table structure show create table my_myisam;

-- Insert data insert into my_myisam values(1),(2),(3);

-- Display data select * from my_myisam;

1

As shown in the figure above, we created a data table named my_myisam with the storage engine being Myisam. In order to verify the storage characteristics of Myisam, we can go to the data folder to view the specific data storage situation:

1

As shown in the figure above, we only created a table my_myisam, but Myisam will generate three storage files, namely:

my_myisam.frm: stores the structure of the table;
my_myisam.MYD: stores table data;
my_myisam.MYI: stores the index of the table.

Now, we copy these three files to the testoo database (as for how to find the storage location of MySQL data files, you can refer to the detailed method of viewing the storage location of MySQL data files):

1

Execute the following SQL statement to test:

-- Switch database use testoo;

-- View the tables in the testoo database show tables;

-- View table my_myisam
select * from my_myisam;

1

As shown in the figure above, we have obviously completed the backup of the data table by copying the file.

Here, there is one thing we need to pay attention to, that is: we can copy the .frm and .idb files generated by the InnoDB storage engine to another database, and we can also view the copied table names through the show tables command, but we cannot obtain the data.

1

Execute the following SQL statement to test:

-- View the tables in the testoo database show tables;

-- View table my_class
select * from my_class;

1

Through the above tests, it is obvious that the data table backup method is more suitable for the Myisam storage engine, and the backup method is also very simple. Just copy the three storage files .frm, .MYD and .MYI generated by the Myisam storage engine to the new database.

Tips: The content enclosed by the symbol [] indicates optional items; the symbol + means connection.

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:
  • The simplest MySQL data backup and restore tutorial in history (Part 2) (Part 36)
  • The simplest MySQL data backup and restore tutorial in history (Part 2) (Part 37)
  • Detailed explanation of MySQL data backup and how to use mysqldump
  • A complete guide to using commands to backup and restore MySQL data under Linux
  • Learn the principles and common operations of MySQL partition tables through examples

<<:  Vue implements the product tab of the product details page function

>>:  Docker container log analysis

Recommend

Design theory: people-oriented design concept

<br />When thoughts were divided into East a...

An article to help you understand the basics of VUE

Table of contents What is VUE Core plugins in Vue...

Example code for implementing dynamic column filtering in vue+element table

Requirement: When displaying data in a list, ther...

Web Design: Web Music Implementation Techniques

<br />When inserting music into a web page, ...

Several ways to encapsulate axios in Vue

Table of contents Basic Edition Step 1: Configure...

How to redraw Button as a circle in XAML

When using XAML layout, sometimes in order to make...

Vue3 encapsulates the side navigation text skeleton effect component

Vue3 project encapsulation side navigation text s...

Detailed explanation of Promises in JavaScript

Table of contents Basic usage of Promise: 1. Crea...

Detailed explanation of MYSQL log and backup and restore issues

This article shares MYSQL logs and backup and res...

Summary of relevant knowledge points of ajax in jQuery

Preface Students who learn JavaScript know that A...

Details on how to use class styles in Vue

Table of contents 1. Boolean 2. Expression 3. Mul...

Hadoop 3.1.1 Fully Distributed Installation Guide under CentOS 6.8 (Recommended)

Foregoing: This document is based on the assumpti...

Introduction to reactive function toRef function ref function in Vue3

Table of contents Reactive Function usage: toRef ...

Analysis of the method of setting up scheduled tasks in mysql

This article uses an example to describe how to s...