五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動(dòng)態(tài)

淺談mysql 針對(duì)單張表的備份與還原

發(fā)布日期:2022-06-17 11:28 | 文章來(lái)源:CSDN

A、MySQL 備份工具xtrabackup 的安裝

1. percona 官方xtrabackup 的二進(jìn)制版本;二進(jìn)制版本解壓就能用了。

2. 解壓xtrabackup & 創(chuàng)建連接

tar -xzvf percona-xtrabackup-2.3.4-Linux-x86_64.tar.gz -C /usr/local/
ln -s /usr/local/percona-xtrabackup-2.3.4 /usr/local/xtrabackup

3. 設(shè)置PATH環(huán)境變量
export PATH=/usr/local/xtrabackup/bin/:$PATH

B、在mysql數(shù)據(jù)庫(kù)中創(chuàng)建一個(gè)用戶備份的用戶 & 授權(quán)

1. 創(chuàng)建用戶

create user backuper@'localhost' identified by 'backup123';
create user backuper@'127.0.0.1' identified by 'backup123';

2. 授權(quán)

grant reload,lock tables,replication client,process,super on *.* to 'backuper'@'localhost';
grant create,insert,select on percona_schema.xtrabackup_history to 'backuper'@'localhost';
grant reload,lock tables,replication client,process,super on *.* to 'backuper'@'127.0.0.1';
grant create,insert,select on percona_schema.xtrabackup_history to 'backuper'@'127.0.0.1';

C、備份前的檢查,這一步的主要目地是在之后做還原操作時(shí),驗(yàn)證還原是不是有效;(生產(chǎn)是沒(méi)有這一步的,

1. select * from tempdb.dict__major;
select * from dict__major;

+--------------+-----------------+
| column_value | column_mean |
+--------------+-----------------+
| 1 | 漢語(yǔ)言文學(xué) |
| 2 | 精算 |
| 3 | 生物制藥 |
| 4 | 材料化學(xué) |
| 5 | 商務(wù)英語(yǔ) |
| 6 | 考古 |
| 7 | 外交 |
| 8 | 導(dǎo)游 |
+--------------+-----------------+

D、備份tempdb.dict__major 表

1. 備份命令

innobackupex --host=127.0.0.1 --user=backuper --password=backup123 --port=3306 --include='tempdb.dict__major' /tmp/tempdb

2. 備份完成后會(huì)在備份目錄(/tmp/tempdb) 下生成用當(dāng)前時(shí)間命名的目錄,里面保存的就是備份文件

tree /tmp/tempdb/
/tmp/tempdb/
└── 2016-09-10_18-25-16
├── backup-my.cnf
├── ibdata1
├── tempdb
│ ├── dict__major.frm
│ └── dict__major.ibd
├── xtrabackup_binlog_info
├── xtrabackup_checkpoints
├── xtrabackup_info
└── xtrabackup_logfile

E、備份完成后就可以刪除tempdb.dict__major表了(注意這里一定要保存一份表的定義,還原時(shí)會(huì)用到)

mysql>drop table tempdb.dict__major;

F、為了得到一個(gè)一致的備份集 在還原操作前還要進(jìn)行一次日志的前滾和回滾

1. 前滾&回滾日志

innobackupex --apply-log --export /tmp/tempdb/2016-09-10_18-25-16/

2. 與前滾& 回滾前的對(duì)比

tree /tmp/tempdb/
/tmp/tempdb/
└── 2016-09-10_18-25-16
├── backup-my.cnf
├── ibdata1
├── ib_logfile0
├── ib_logfile1
├── tempdb
│ ├── dict__major.cfg
│ ├── dict__major.exp
│ ├── dict__major.frm
│ └── dict__major.ibd
├── xtrabackup_binlog_info
├── xtrabackup_binlog_pos_innodb
├── xtrabackup_checkpoints
├── xtrabackup_info
└── xtrabackup_logfile

G、還原tempdb.dict__major表

1. 創(chuàng)建 tempdb.dict__major表

create table dict__major(
column_value tinyint not null,
column_mean varchar(32) not null,
constraint pk__dict__major primary key (column_value));

2. 刪除 tempdb.dict__major的表空間文件

alter table tempdb.dict__major discard tablespace;

3. 把備份中的表空間文件復(fù)制到tempdb.dict__major 表空間應(yīng)該在的位置

cp /tmp/tempdb/2016-09-10_18-25-16/tempdb/dict__major.ibd /usr/local/mysql/data/tempdb/
cp /tmp/tempdb/2016-09-10_18-25-16/tempdb/dict__major.exp /usr/local/mysql/data/tempdb/
cp /tmp/tempdb/2016-09-10_18-25-16/tempdb/dict__major.cfg /usr/local/mysql/data/tempdb/
chown -R mysql:mysql /usr/local/mysql/data/tempdb/*

4. 導(dǎo)入表空間文件

alter table tempdb.dict__major import tablespace;

5. 查看dict__major表恢復(fù)情況

select * from dict__major;
+--------------+-----------------+
| column_value | column_mean |
+--------------+-----------------+
| 1 | 漢語(yǔ)言文學(xué) |
| 2 | 精算 |
| 3 | 生物制藥 |
| 4 | 材料化學(xué) |
| 5 | 商務(wù)英語(yǔ) |
| 6 | 考古 |
| 7 | 外交 |
| 8 | 導(dǎo)游 |
+--------------+-----------------+

---------------------------------------------------------------

上一節(jié)用的是xtrabackup 對(duì)表進(jìn)行備份,它的應(yīng)用場(chǎng)景是單表的數(shù)據(jù)量大且在備份的過(guò)程中還要支持對(duì)表的寫操作;也就是說(shuō)在目前的場(chǎng)景下mysqldump 這個(gè)簡(jiǎn)單的

備份工具也是可以滿足要求的;


現(xiàn)給出mysqldump 備份的一般步驟

A:創(chuàng)建備份用戶

1.
create user dumper@'127.0.0.1' identified by 'dumper123';
grant select on *.* to dumper@'127.0.0.1';
grant show view on *.* to dumper@'127.0.0.1';
grant lock tables on *.* to dumper@'127.0.0.1';
grant trigger on *.* to dumper@'127.0.0.1';

B:備份tempdb.dict__major表

1.
mysqldump --host=127.0.0.1 --port=3306 --user=dumper --password=dumper123 --quick tempdb dict__major >/tmp/tempdb.dict__major.sql

C: 刪除已經(jīng)備份的表

1.
mysql>drop table tempdb.dict__major;

D:還原tempdb.dict__major表

1.
mysql -uroot -pxxxxx -h127.0.0.1 -p3306 tempdb </tmp/tempdb.dict__major.sql

E:檢證還原的有效性

1.
select * from dict__major;

+--------------+-----------------+
| column_value | column_mean |
+--------------+-----------------+
| 1 | 漢語(yǔ)言文學(xué) |
| 2 | 精算 |
| 3 | 生物制藥 |
| 4 | 材料化學(xué) |
| 5 | 商務(wù)英語(yǔ) |
| 6 | 考古 |
| 7 | 外交 |
| 8 | 導(dǎo)游 |
+--------------+-----------------+

以上這篇淺談mysql 針對(duì)單張表的備份與還原就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持本站。

香港快速服務(wù)器

版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問(wèn)服務(wù)

1對(duì)1客戶咨詢顧問(wèn)

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部