MySQL restores the specified table and database example from full-database backup. mysql example

Source: Internet
Author: User

MySQL restores the specified table and database example from full-database backup. mysql example

MySQL restores the specified table and database example from the backup database

In the official Mysqldump tool, how does one restore a database?

Full database backup

[Root @ HE1 ~] # Mysqldump-uroot-p -- single-transaction-A -- master-data = 2> dump. SQL

Only restore the content of the erp Database

[Root @ HE1 ~] # Mysql-uroot-pMANAGER erp -- one-database <dump. SQL

We can see that the main parameter used here is -- one-database short-o, which greatly facilitates our recovery flexibility.

So how can we extract a table from the full database backup, recover the whole database, and restore a small table 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 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 SETcharacter_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 table t content from full database backup

[Root @ HE1 ~] # Grep 'insert INTO 't''dump. SQL
Insert into 't'values (, ''), (, 'A'), (, 'bbb '), (, 'helei ');

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.