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

Interpretation of 17 advertising effectiveness measures

1. 85% of ads go unread <br />Interpretatio...

Practical experience of implementing nginx to forward requests based on URL

Preface Because this is a distributed file system...

Detailed explanation of the use of Vue.js draggable text box component

Table of contents Registering Components Adding C...

Linux Operation and Maintenance Basic System Disk Management Tutorial

1. Disk partition: 2. fdisk partition If the disk...

A permanent solution to MYSQL's inability to recognize Chinese

In most cases, MySQL does not support Chinese whe...

MySQL full-text fuzzy search MATCH AGAINST method example

MySQL 4.x and above provide full-text search supp...

Example code for setting hot links and coordinate values ​​for web images

Sometimes you need to set several areas on a pict...

Mysql slow query optimization method and optimization principle

1. For comparison of date size, the date format p...

CentOS uses local yum source to build LAMP environment graphic tutorial

This article describes how to use the local yum s...

How to implement animation transition effect on the front end

Table of contents Introduction Traditional transi...

Complete steps to solve 403 forbidden in Nginx

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

How a select statement is executed in MySQL

Table of contents 1. Analyzing MySQL from a macro...

JavaScript Sandbox Exploration

Table of contents 1. Scenario 2. Basic functions ...