How to restore a database and a table from a MySQL full database backup

How to restore a database and a table from a MySQL full database backup

In the official MySQL dump tool, how can I restore only a certain database?

Full database backup

[root@HE1 ~]# mysqldump -uroot -p --single-transaction -A --master-data=2 >dump.sql

Only restore the contents of the erp library

[root@HE1 ~]# mysql -uroot -pMANAGER erp --one-database <dump.sql

It can be seen that the main parameter used here is the --one-database abbreviated as -o, which greatly facilitates our recovery flexibility.

So how do we extract a table from the full database backup? Restoring the entire database and then restoring a table is OK for a small database, but it is very troublesome for a large database. Then we can use regular expressions for quick extraction. The specific implementation method is as follows:

Extract the table structure of table t from the full database backup

[root@HE1 ~]# sed -e'/./{H;$!d;}' -e 'x;/CREATE TABLE `t`/!d;q' dump.sql

DROP TABLE IF EXISTS `t`;

/*!40101 SET @saved_cs_client = @@character_set_client */;

/*!40101 SET character_set_client = utf8 */;

CREATE TABLE `t` (

 `id` int(10) NOT NULL AUTO_INCREMENT,

 `age` tinyint(4) NOT NULL DEFAULT '0',

 `name` varchar(30) NOT NULL DEFAULT '',

 PRIMARY KEY (`id`)

)ENGINE=InnoDBAUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

/*!40101 SETcharacter_set_client = @saved_cs_client */;

Extract the contents of the t table from the full database backup

[root@HE1 ~]# grep'INSERT INTO `t`' dump.sql

INSERT INTO `t`VALUES (0,0,''),(1,0,'aa'),(2,0,'bbb'),(3,25,'helei');

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:
  • How to restore single table data using MySQL full database backup data
  • How to restore a single database or table in MySQL and possible pitfalls
  • Steps for restoring a single MySQL table
  • 3 methods to restore table structure from frm file in mysql [recommended]
  • InnoDB type MySql restore table structure and data
  • MySQL restore specified tables and libraries from full database backup example
  • Detailed explanation of MySQL single table ibd file recovery method
  • MYSQL uses .frm to restore the data table structure
  • How to use mysqldump to backup and restore specified tables
  • MySQL uses frm files and ibd files to restore table data

<<:  Vue mobile terminal realizes finger sliding effect

>>:  How to solve the problem of character set when logging in to Linux

Recommend

VMware Workstation is not compatible with Device/Credential Guard

When installing a virtual machine, a prompt appea...

CSS3 realizes bouncing ball animation

I usually like to visit the special pages or prod...

Hyper-V Introduction and Installation and Use (Detailed Illustrations)

Preface: As a giant in the IT industry, Microsoft...

How to find out uncommitted transaction information in MySQL

A while ago, I wrote a blog post titled "Can...

Mysql master-slave synchronization Last_IO_Errno:1236 error solution

What is the reason for the Last_IO_Errno:1236 err...

HTML embedded in WMP compatible with Chrome and IE detailed introduction

In fact, there are many corresponding writing met...

Complete steps to build a squid proxy server in linux

Preface This article mainly introduces the releva...

Solve the error during connect exception in Docker

When you first start using Docker, you will inevi...

MySQL Tutorial: Subquery Example Detailed Explanation

Table of contents 1. What is a subquery? 2. Where...

Explanation of the usage scenarios of sql and various nosql databases

SQL is the main trunk. Why do I understand it thi...

Detailed explanation of Vue development Sort component code

Table of contents <template> <ul class=&...

Echarts tutorial on how to implement tree charts

Treemaps are mainly used to visualize tree-like d...