這篇文章主要介紹“MySQL數(shù)據(jù)庫(kù)的備份與恢復(fù)方法”,在日常操作中,相信很多人在Mysql數(shù)據(jù)庫(kù)的備份與恢復(fù)方法問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Mysql數(shù)據(jù)庫(kù)的備份與恢復(fù)方法”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
八宿網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,八宿網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為八宿1000+提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的八宿做網(wǎng)站的公司定做!
1.備份cancer數(shù)據(jù)庫(kù)
```
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| cancer |
| cancer_utf8 |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.05 sec)
```
2.備份的方向符號(hào)為(>)
```
[root@mysql 3306]# mysqldump -uroot -p -S /data/3306/mysql.sock cancer >/opt/cancer_bak.sql
Enter password:
```
3.查看備份的語(yǔ)句
```
[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.備份恢復(fù)的方向符號(hào)為(<)
```
[root@mysql 3306]# mysql -uroot -p -S /data/3306/mysql.sock cancer </opt/cancer_bak.sql
```
加-B的備份與恢復(fù)
1.備份
```
[root@mysql 3306]# mysqldump -uroot -p -S /data/3306/mysql.sock -B cancer >/opt/cancer_bak_B.sql
Enter password:
[root@mysql 3306]# cd /opt
[root@mysql opt]# diff cancer_bak.sql cancer_bak_B.sql
18a19,26
> -- 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
```
2.恢復(fù)
```
[root@mysql opt]# mysql -uroot -p -S /data/3306/mysql.sock </opt/cancer_bak_B.sql
```
3.壓縮備份
```
[root@mysql opt]# mysqldump -uroot -p -S /data/3306/mysql.sock -B cancer|gzip >/opt/cancer_bak_gzip.sql.gz
Enter password:
```
4.備份多個(gè)庫(kù)
```
[root@mysql opt]# mysqldump -uroot -p -S /data/3306/mysql.sock -B cancer cancer_utf8 >/opt/cancer_mul_bak
Enter password:
```
5.多庫(kù)備份腳本
```
[root@mysql opt]# mysql -uroot -p -S /data/3306/mysql.sock -e "show databases;"|grep -Evi "database|infor|perfor"|sed -r 's#^([a-z].*$)#mysqldump -uroot -pcancer -S /data/3306/mysql.sock -B --events \1|gzip >/opt/\1.sql.gz#g'|bash
Enter password:
```
腳本的顯示內(nèi)容
```
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.備份具體某個(gè)庫(kù)中的某個(gè)表
```
[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 */;
```
2.只備份表結(jié)構(gòu)
```
[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.只備份數(shù)據(jù)
```
[root@mysql ~]# mysqldump -uroot -p -S /data/3306/mysql.sock -t cancer student
Enter password:
INSERT INTO `student` VALUES (1,'???'),(2,'è???”·?-?');
```
到此,關(guān)于“Mysql數(shù)據(jù)庫(kù)的備份與恢復(fù)方法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
分享名稱:Mysql數(shù)據(jù)庫(kù)的備份與恢復(fù)方法
網(wǎng)站鏈接:http://muchs.cn/article42/gesdhc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、域名注冊(cè)、微信公眾號(hào)、網(wǎng)站內(nèi)鏈、自適應(yīng)網(wǎng)站、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)