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

Sample code for configuring nginx to support https

1. Introduction Are you still leaving your websit...

Detailed explanation of Linux server status and performance related commands

Server Status Analysis View Linux server CPU deta...

Font references and transition effects outside the system

Copy code The code is as follows: <span style=...

How to use Nexus to add jar packages to private servers

Why do we need to build a nexus private server? T...

How to expand the disk size of a virtual machine

After Vmvare sets the disk size of the virtual ma...

CSS3 realizes the childhood paper airplane

Today we are going to make origami airplanes (the...

Complete steps to solve 403 forbidden in Nginx

The webpage displays 403 Forbidden Nginx (yum ins...

Analysis and solution of MySQL connection throwing Authentication Failed error

[Problem description] On the application side, th...

VMWare virtual machine 15.X LAN network configuration tutorial diagram

Recently, I have been working on several virtual ...

Understand the basics of Navicat for MySQL in one article

Table of contents 1. Database Operation 2. Data T...

When the interviewer asked the difference between char and varchar in mysql

Table of contents Difference between char and var...

CentOS 7 builds hadoop 2.10 high availability (HA)

This article introduces how to build a high-avail...

Talk about how to identify HTML escape characters through code

Occasionally you'll see characters such as &#...