In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "the backup and recovery method of Mysql database". In the daily operation, I believe that many people have doubts about the backup and recovery method of Mysql database. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "backup and recovery method of Mysql database". Next, please follow the editor to study!
1. Back up the cancer database
`
Mysql > show databases
+-+
| | Database |
+-+
| | information_schema |
| | mysql |
| | cancer |
| | cancer_utf8 |
| | performance_schema |
| | test |
+-+
6 rows in set (0.05 sec)
`
two。 The direction symbol of the backup is (>)
`
[root@mysql 3306] # mysqldump-uroot-p-S / data/3306/mysql.sock cancer > / opt/cancer_bak.sql
Enter password:
`
3. View statements for backup
`
[root@mysql 3306] # egrep-v "# |\ * |-- | ^ $" / opt/cancer_bak.sql
DROP TABLE IF EXISTS `student`
CREATE TABLE `student` (
`id`int (4) NOT NULL AUTO_INCREMENT
`names` char (20) NOT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
LOCK TABLES `student` WRITE
INSERT INTO `student`VALUES (1), (2)
UNLOCK TABLES
`
4. The direction symbol for backup and recovery is (--Current Database: `cancer`
>--
>
> CREATE DATABASE / *! 32312 IF NOT EXISTS*/ `cancer` / *! 40100 DEFAULT CHARACTER SET latin1 * /
>
> USE `cancer`
>
>--
51c59
< -- Dump completed on 2015-08-16 16:16:33 --- >-- Dump completed on 2015-08-16 16:22:32
`
two。 Restore
`
[root@mysql opt] # mysql-uroot-p-S / data/3306/mysql.sock / opt/cancer_bak_gzip.sql.gz
Enter password:
`
4. Back up multiple libraries
`
[root@mysql opt] # mysqldump-uroot-p-S / data/3306/mysql.sock-B cancer cancer_utf8 > / opt/cancer_mul_bak
Enter password:
`
5. Multi-library backup script
`
[root@mysql opt] # mysql-uroot-p-S / data/3306/mysql.sock-e "show databases;" | grep-Evi "database | infor | perfor" | sed-r's # ^ ([Amurz]. * $) # mysqldump-uroot-pcancer-S / data/3306/mysql.sock-B-events\ 1 | gzip > / opt/\ 1.sql.gzroomg' | bash
Enter password:
`
The display of the script
`
Mysqldump-uroot-pcancer-S / data/3306/mysql.sock-B mysql | gzip > / opt/mysql.sql.gz
Mysqldump-uroot-pcancer-S / data/3306/mysql.sock-B cancer | gzip > / opt/cancer.sql.gz
Mysqldump-uroot-pcancer-S / data/3306/mysql.sock-B cancer_utf8 | gzip > / opt/cancer_utf8.sql.gz
Mysqldump-uroot-pcancer-S / data/3306/mysql.sock-B test | gzip > / opt/test.sql.gz
`
1. Back up a table in a specific library
`
[root@mysql] # mysqldump-uroot-p-S / data/3306/mysql.sock cancer student test
Enter password:
/ *! 40101 SET @ saved_cs_client = @ @ character_set_client * /
/ *! 40101 SET character_set_client = utf8 * /
CREATE TABLE `student` (
`id`int (4) NOT NULL AUTO_INCREMENT
`names` char (20) NOT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
/ * 40101 SET character_set_client = @ saved_cs_client * /
INSERT INTO `student`VALUES (1), (2)
/ *! 40101 SET @ saved_cs_client = @ @ character_set_client * /
/ *! 40101 SET character_set_client = utf8 * /
CREATE TABLE `test` (
`id`int (11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/ * 40101 SET character_set_client = @ saved_cs_client * /
`
two。 Backup list structure only
`
[root@mysql] # mysqldump-uroot-p-S / data/3306/mysql.sock-d cancer
Enter password:
/ *! 40101 SET @ saved_cs_client = @ @ character_set_client * /
/ *! 40101 SET character_set_client = utf8 * /
CREATE TABLE `student` (
`id`int (4) NOT NULL AUTO_INCREMENT
`names` char (20) NOT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
/ * 40101 SET character_set_client = @ saved_cs_client * /
/ *! 40101 SET @ saved_cs_client = @ @ character_set_client * /
/ *! 40101 SET character_set_client = utf8 * /
CREATE TABLE `test` (
`id`int (11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/ * 40101 SET character_set_client = @ saved_cs_client * /
`
`
[root@mysql] # mysqldump-uroot-p-S / data/3306/mysql.sock-d cancer student
Enter password:
/ *! 40101 SET @ saved_cs_client = @ @ character_set_client * /
/ *! 40101 SET character_set_client = utf8 * /
CREATE TABLE `student` (
`id`int (4) NOT NULL AUTO_INCREMENT
`names` char (20) NOT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
/ * 40101 SET character_set_client = @ saved_cs_client * /
`
3. Back up data only
`
[root@mysql] # mysqldump-uroot-p-S / data/3306/mysql.sock-t cancer student
Enter password:
INSERT INTO `student`VALUES (1), (2)
`
At this point, the study of "backup and recovery methods of Mysql database" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.