bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

MySQL全量、增量備份與恢復(fù)

數(shù)據(jù)備份的重要性

創(chuàng)新互聯(lián)公司網(wǎng)站建設(shè)公司一直秉承“誠(chéng)信做人,踏實(shí)做事”的原則,不欺瞞客戶,是我們最起碼的底線! 以服務(wù)為基礎(chǔ),以質(zhì)量求生存,以技術(shù)求發(fā)展,成交一個(gè)客戶多一個(gè)朋友!專注中小微企業(yè)官網(wǎng)定制,網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站,塑造企業(yè)網(wǎng)絡(luò)形象打造互聯(lián)網(wǎng)企業(yè)效應(yīng)。

  • 在生產(chǎn)環(huán)境中,數(shù)據(jù)的安全性是至關(guān)重要的,任何數(shù)據(jù)的丟失都可能產(chǎn)生嚴(yán)重的后果
  • 造成數(shù)據(jù)丟失的原因
    1.程序錯(cuò)誤
    2.人為錯(cuò)誤
    3.計(jì)算機(jī)失敗
    4.磁盤失敗
    5.zai難和偷竊
    數(shù)據(jù)庫(kù)備份的分類
  • 物理備份: 對(duì)數(shù)據(jù)庫(kù)操作系統(tǒng)的物理文件(如數(shù)據(jù)文件、日志文件等)的備份
    物理備份又可分為脫機(jī)備份(冷備份)和聯(lián)機(jī)備份(熱備份)
    -冷備份:是在關(guān)閉數(shù)據(jù)庫(kù)的時(shí)候進(jìn)行的
    -熱備份:數(shù)據(jù)庫(kù)處于運(yùn)行狀態(tài),這種備份方法依賴于數(shù)據(jù)庫(kù)的日志文件
  • 邏輯備份:對(duì)數(shù)據(jù)庫(kù)組件(如表等數(shù)據(jù)庫(kù)對(duì)象)的備份
    表:表的結(jié)構(gòu)文件(FRM)、數(shù)據(jù)文件(MYD)、索引文件(MYI)
    從數(shù)據(jù)庫(kù)的備份策略角度,備份可分為
    1.完全備份
  • 每次對(duì)數(shù)據(jù)進(jìn)行完整的備份
    完全備份:會(huì)把服務(wù)器內(nèi)的所有數(shù)據(jù)全部備份,每次都這么執(zhí)行
    優(yōu)點(diǎn):安全
    缺點(diǎn):數(shù)據(jù)備份冗余,占用磁盤空間
    2.差異備份
  • 備份那些自從上次完全備份之后被修改過(guò)的文件
  • 前提是必須要備份一次完全備份,接下來(lái)每次只備份基于完全備份的基礎(chǔ)上被修改過(guò)的文件
    3.增量備份
  • 只有那些在上次完全備份或者增量備份后被修改的文件才會(huì)被備份
    差異備份與增量備份比較:
    相同點(diǎn):基礎(chǔ)都是完全備份
    不同點(diǎn):差異備份只參考基礎(chǔ)的完全備份,
    增量備份是參考上一次的數(shù)據(jù)備份與當(dāng)前狀態(tài)進(jìn)行對(duì)比,備份被修改的文件
    增量備份效率更高,空間利用率很高,但是在安全性能不高
    MySQL完全備份
  • 完全備份是對(duì)整個(gè)數(shù)據(jù)庫(kù)的備份、數(shù)據(jù)庫(kù)結(jié)構(gòu)和文件結(jié)構(gòu)的備份
  • 完全備份保存的是備份完成時(shí)刻的數(shù)據(jù)庫(kù)
  • 完全備份是增量備份的基礎(chǔ)
    完全備份的優(yōu)缺點(diǎn)
  • 優(yōu)點(diǎn)
    備份與恢復(fù)操作簡(jiǎn)單方便
  • 缺點(diǎn)
    數(shù)據(jù)存在大量的重復(fù)
    占用大量的備份空間
    備份與恢復(fù)空間長(zhǎng)
    mysqldump備份庫(kù)
    mysqldump備份庫(kù)概述
    mysql數(shù)據(jù)庫(kù)的備份可以采用多種方式
  • 直接打包數(shù)據(jù)庫(kù)文件夾,如/usr/local/mysql/data————這種是物理層面的備份
  • 使用專業(yè)備份工具 mysqldump————這種事邏輯層面的備份
    mysqldump命令對(duì)庫(kù)備份
  • mysql自帶的備份工具,相當(dāng)方便對(duì)mysql進(jìn)行備份
  • 通過(guò)該命令工具可以將指定的庫(kù)、表或全部的庫(kù)導(dǎo)出為sql腳本,在需要恢復(fù)時(shí)可進(jìn)行數(shù)據(jù)恢復(fù)
    MySQL全量、增量備份與恢復(fù)
    MySQL全量、增量備份與恢復(fù)
    MySQL全量、增量備份與恢復(fù)
    MySQL全量、增量備份與恢復(fù)

實(shí)操
創(chuàng)建數(shù)據(jù)庫(kù)、表、插入數(shù)據(jù)
MySQL全量、增量備份與恢復(fù)
MySQL全量、增量備份與恢復(fù)
MySQL全量、增量備份與恢復(fù)
mysqldump命令對(duì)單個(gè)庫(kù)進(jìn)行完全備份
添加多個(gè)數(shù)據(jù)庫(kù)

[root@localhost mysql]# mysqldump -u root -p school > /opt/school.sql
Enter password: 
[root@localhost mysql]# ls /opt/
dir_SC_UTF8              mysql-5.7.20  php-7.1.10  school.sql
mysql-2020-01-07.tar.xz  nginx-1.12.2  rh          說(shuō)明.htm
[root@localhost mysql]# cd /opt
[root@localhost opt]# ls school.sql 
school.sql
[root@localhost opt]# vim school.sql 
[root@localhost opt]# 

mysqldump命令對(duì)多個(gè)庫(kù)進(jìn)行完全備份

  • mysqdump -u 用戶名 -p [密碼] [選項(xiàng)] --databases 庫(kù)名1 [庫(kù)名2]… > /備份路徑/備份文件名
    多庫(kù)備份舉例
  • mysqldump -u root -p --databases auth mysql > /backup/databases-auth-mysql.sql
    對(duì)所有庫(kù)進(jìn)行完全備份
  • mysqdump -u 用戶名 -p [密碼] [選項(xiàng)] --all-databases > /備份路徑/備份文件名
    所有庫(kù)備份舉例
  • mysqldump -u root -p --opt --all-databases > /backup/all-data.sql
    使用mysqldump備份表的操作
  • mysqdump -u 用戶名 -p [密碼] [選項(xiàng)] 數(shù)據(jù)庫(kù)名 表名 > /備份路徑/備份文件名
    備份表的舉例
  • mysqldump -u root -p mysql user > /backup/mysql-user.sql
    [root@localhost opt]# mysqldump -uroot -p12341234 school info > /opt/school_info.sql
    mysqldump: [Warning] Using a password on the command line interface can be insecure.
    [root@localhost opt]# ls /opt/school_info.sql 
    /opt/school_info.sql
    [root@localhost opt]# vim /opt/school_info.sql 

    基于表結(jié)構(gòu)的備份

    [root@localhost opt]# mysqldump -uroot -p12341234 -d school info > /opt/school_infod.sql
    mysqldump: [Warning] Using a password on the command line interface can be insecure.
    [root@localhost opt]# vim /opt/school_infod.sql 

    恢復(fù)數(shù)據(jù)庫(kù)
    使用musqldump命令導(dǎo)出的SQL備份腳本,在進(jìn)行數(shù)據(jù)恢復(fù)時(shí)可使用以下方法導(dǎo)入

  • source命令
  • mysql命令
    注意:source命令是在mysql模式下面使用;mysql命令是在linux模式下使用。
    使用source恢復(fù)數(shù)據(jù)庫(kù)的步驟
    登錄到mysql數(shù)據(jù)庫(kù)
    執(zhí)行source 備份sql腳本的路徑
    mysql [(none)] > source /backup/all-data.sql

    示例:
    備注:備份sql腳本的路徑寫絕對(duì)路徑
    恢復(fù)數(shù)據(jù)庫(kù),是恢復(fù)數(shù)據(jù)庫(kù)里面的表,如果此時(shí)數(shù)據(jù)庫(kù)也被刪除,需要?jiǎng)?chuàng)建一個(gè)同名的數(shù)據(jù)庫(kù)————仔細(xì)查看school.sql腳本,可以發(fā)現(xiàn)沒(méi)有school數(shù)據(jù)庫(kù)的操作

[root@localhost opt]# mysql -uroot -p
Enter password: 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bbs                |
| mysql              |
| performance_schema |
| school             |
| sys                |
+--------------------+
6 rows in set (0.00 sec)

mysql> use school;
Database changed

mysql> drop table info;
Query OK, 1 row affected (0.01 sec)
mysql> show tables;
Empty set (0.00 sec)

mysql> source /opt/school.sql
Query OK, 0 rows affected (0.00 sec)
......
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| info             |
+------------------+
1 row in set (0.00 sec)

使用mysql命令恢復(fù)數(shù)據(jù)
mysql -u -p [密碼] < 庫(kù)備份腳本的路徑

mysql> drop table info;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
Empty set (0.00 sec)
mysql> quit
Bye
[root@localhost opt]# 
[root@localhost opt]# mysql -uroot -p12341234 school < /opt/school.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost opt]# mysql -uroot -p
Enter password: 
mysql> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| info             |
+------------------+
1 row in set (0.00 sec)
mysql> select * from info;
+----+-------+-------+
| id | name  | score |
+----+-------+-------+
|  1 | stu01 |  88.0 |
|  2 | stu02 |  77.0 |
+----+-------+-------+
2 rows in set (0.00 sec)

mysql 命令恢復(fù)舉例

  • mysql -u -p < /backup/all-data.sql

恢復(fù)表的操作

  • 恢復(fù)表時(shí)同樣可以使用source或者mysql命令進(jìn)行
  • source恢復(fù)表的操作與恢復(fù)庫(kù)的操作相同
  • 當(dāng)備份文件中只包含表的備份,而不包括創(chuàng)建庫(kù)的語(yǔ)句是,必須指定庫(kù)名,切目標(biāo)庫(kù)必須存在
mysql   -u  用戶名 -p  [密碼]    <   表備份腳本的路徑
mysql -u -p mysql < /backup/mysql-user.sql

mysql備份思路:
定期實(shí)施備份,制定備份計(jì)劃或者策略,并嚴(yán)格遵守
除了進(jìn)行完全備份,開(kāi)啟mysql服務(wù)器的日志功能是很重要的
完全備份加上日志,可以對(duì)mysql進(jìn)行最大化還原
使用統(tǒng)一的和易理解的備份文件名稱
不要使用backup1/2這樣沒(méi)有意義的名字
推薦使用庫(kù)名或者表名加上時(shí)間的命名規(guī)則
備份文件名使用時(shí)間+業(yè)務(wù)名+庫(kù)名
要開(kāi)啟服務(wù)器的日志功能

mysql增量備份
誕生增量備份的原因
解決使用mysqldump進(jìn)行完全備份時(shí)的存在的問(wèn)題

  • 備份數(shù)據(jù)中有重復(fù)數(shù)據(jù),會(huì)造成數(shù)據(jù)冗余、占用磁盤空間
  • 備份時(shí)間與回復(fù)時(shí)間長(zhǎng)
    增量備份就是備份上一次備份之后增加或變化的文件或內(nèi)容
    增量備份的優(yōu)缺點(diǎn):
    優(yōu)點(diǎn):沒(méi)有重復(fù)數(shù)據(jù),備份量不大,時(shí)間短
    缺點(diǎn):恢復(fù)麻煩;需要上次完全備份及完全備份之后所有的增量備份才能恢復(fù),而且要對(duì)所有增量備份進(jìn)行逐個(gè)反推恢復(fù)
    通過(guò)mysql的二進(jìn)制日志文件分割間接實(shí)現(xiàn)增量備份
  • mysql沒(méi)有提供直接的增量備份方法
  • 可以通過(guò)mysql提供的二進(jìn)制文件(binary logs)間接實(shí)現(xiàn)增量備份
  • mysql二進(jìn)制日志對(duì)備份的意義
    二進(jìn)制日志保存了所有更新或者可能更新數(shù)據(jù)庫(kù)的操作
    二進(jìn)制日志在啟動(dòng)mysql服務(wù)器后開(kāi)始記錄,并在文件達(dá)到maxbinlogsize所設(shè)置的大小或者接收到flush logs命令后重新創(chuàng)建新的日志文件
    只需定時(shí)執(zhí)行flush logs方法重新創(chuàng)建新的日志,生成二進(jìn)制文件序列,并及時(shí)把這些舊的日志保存到安全的地方就完成了一個(gè)時(shí)間段的增量備份
  • 二進(jìn)制文件針對(duì)位置點(diǎn)、時(shí)間點(diǎn)進(jìn)行有效的恢復(fù)
  • 查看日志文件需要進(jìn)行解碼
    mysql數(shù)據(jù)庫(kù)增量恢復(fù)
    mysqlbinlog [–no-defaults] 增量備份文件 | mysql -u 用戶名 -p

    基于位置恢復(fù)
    就是將某個(gè)起始時(shí)間的二進(jìn)制日志導(dǎo)入到數(shù)據(jù)庫(kù)中,從而跳過(guò)某個(gè)發(fā)生錯(cuò)誤的時(shí)間點(diǎn)實(shí)現(xiàn)數(shù)據(jù)的恢復(fù)
    命令:

    #恢復(fù)數(shù)據(jù)到指定位置
    mysqlbinlog --stop-position=‘操作 id’ 二進(jìn)制日志 | mysql -u 用戶名 -p 密碼
    #從指定的位置開(kāi)始恢復(fù)數(shù)據(jù)
    mysqlbinlog --start-position=‘操作 id’ 二進(jìn)制日志 | mysql -u 用戶名 -p 密碼

    基于時(shí)間點(diǎn)恢復(fù)
    使用基于時(shí)間點(diǎn)的恢復(fù),可能會(huì)出現(xiàn)在一個(gè)時(shí)間點(diǎn)里既同時(shí)存在正確的操作又存在錯(cuò)誤的操作,所以我們需要一種更為精確的恢復(fù)方式
    針對(duì)過(guò)程中的誤操作備份,如何跳過(guò)誤操作的方式————可以進(jìn)行斷點(diǎn)恢復(fù)
    語(yǔ)法:

    #從日志開(kāi)頭截止到某個(gè)時(shí)間點(diǎn)的恢復(fù)
    mysqlbinlog [–no-defaults] --stop-datetime=‘年-月-日 小時(shí):分鐘:秒’ 二進(jìn)制日志 | mysql -u 用戶名 -p 密碼
    #從某個(gè)時(shí)間點(diǎn)到日志結(jié)尾的恢復(fù)
    mysqlbinlog [–no-defaults] --start-datetime=‘年-月-日 小時(shí):分鐘:秒’ 二進(jìn)制日志 | mysql -u 用戶名 -p 密碼
    #從某個(gè)時(shí)間點(diǎn)到某個(gè)時(shí)間點(diǎn)的恢復(fù)
    mysqlbinlog [–no-defaults] --start-datetime=‘年-月-日 小時(shí):分鐘:秒’ --stop-datetime=‘年-月-日 小時(shí):分鐘:秒’ 二進(jìn)制日志 | mysql -u 用戶名 -p 密碼

    實(shí)操

    [root@localhost opt]# ls
    all.sql                  mysql-5.7.20  school_infod.sql
    db_school_mysql.sql      nginx-1.12.2  school_info.sql
    dir_SC_UTF8              php-7.1.10    school.sql
    mysql-2020-01-07.tar.xz  rh            說(shuō)明.htm
    [root@localhost opt]# rm -rf *.sql
    [root@localhost opt]# ls
    dir_SC_UTF8              mysql-5.7.20  php-7.1.10  說(shuō)明.htm
    mysql-2020-01-07.tar.xz  nginx-1.12.2  rh

    開(kāi)啟二進(jìn)制日志功能,修改/etc/my.cnf文件,然后重啟服務(wù)

[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
'log-bin=mysql-bin
server-id = 1
default-storage-engine=Myisam

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
[root@localhost opt]# systemctl restart mysqld

查看二進(jìn)制日志文件

[root@localhost opt]# cd /usr/local/mysql/
[root@localhost mysql]# cd data/
[root@localhost data]# ls
auto.cnf        ibdata1      ibtmp1            mysql-bin.index     sys
bbs             ib_logfile0  mysql             performance_schema
ib_buffer_pool  ib_logfile1  'mysql-bin.000001'  school
[root@localhost data]# 

做增量備份前,要先進(jìn)行一次完全備份

[root@localhost data]# mysqldump -uroot -p12341234 school > /opt/school.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@localhost data]# cd /opt
[root@localhost opt]# ls
dir_SC_UTF8              mysql-5.7.20  php-7.1.10  school.sql
mysql-2020-01-07.tar.xz  nginx-1.12.2  rh          說(shuō)明.htm
[root@localhost opt]# vim school.sql 

接下來(lái)做增量備份,此時(shí),之前的操作被存放到001當(dāng)中,接下來(lái)的操作會(huì)被存放到002當(dāng)中

[root@localhost opt]# mysqladmin -uroot -p12341234 flush-logs
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@localhost opt]# ls /usr/local/mysql/data/
auto.cnf        ibdata1      ibtmp1            mysql-bin.000002    school
bbs             ib_logfile0  mysql             mysql-bin.index     sys
ib_buffer_pool  ib_logfile1  mysql-bin.000001  performance_schema
mysql> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from info;
+----+-------+-------+
| id | name  | score |
+----+-------+-------+
|  1 | stu01 |  88.0 |
|  2 | stu02 |  77.0 |
+----+-------+-------+
2 rows in set (0.00 sec)

mysql> insert into info (name,score) values ('test01',66);
//這個(gè)是正常操作
Query OK, 1 row affected (0.00 sec)

mysql> select * from info;
+----+--------+-------+
| id | name   | score |
+----+--------+-------+
|  1 | stu01  |  88.0 |
|  2 | stu02  |  77.0 |
|  3 | test01 |  66.0 |
+----+--------+-------+
3 rows in set (0.00 sec)

mysql> delete from info where name='stu01';
//誤操作
Query OK, 1 row affected (0.01 sec)

mysql> insert into info (name,score) values ('test02',99);
//正常操作
Query OK, 1 row affected (0.01 sec)

mysql> select * from info;
+----+--------+-------+
| id | name   | score |
+----+--------+-------+
|  4 | test02 |  99.0 |
|  2 | stu02  |  77.0 |
|  3 | test01 |  66.0 |
+----+--------+-------+
3 rows in set (0.01 sec)
mysql> quit
Bye

此時(shí)在不知情的情況下,進(jìn)行增量備份,此時(shí)誤操作寫在了002中

[root@localhost opt]# mysqladmin -uroot -p12341234 flush-logs
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@localhost opt]# cd /usr/local/mysql/data/
[root@localhost data]# ls
auto.cnf        ib_logfile0  mysql-bin.000001  performance_schema
bbs             ib_logfile1  mysql-bin.000002  school
ib_buffer_pool  ibtmp1       mysql-bin.000003  sys
ibdata1         mysql        mysql-bin.index

查看日志文件:-v 顯示內(nèi)容在界面,–base64解碼器 output輸出 decode-rows 讀取按行讀取

[root@localhost data]# mysqlbinlog --no-defaults mysql-bin.000002 
//查看二進(jìn)制日志文件,不過(guò)可以發(fā)現(xiàn)看不懂
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
//這個(gè)是位置點(diǎn)
#200107 16:54:11 server id 1  end_log_pos 123 CRC32 0x76a9dc26  Start: binlog v 4, server v 5.7.20-log created 200107 16:54:11
//這個(gè)是時(shí)間點(diǎn)
BINLOG '
M0cUXg8BAAAAdwAAAHsAAAAAAAQANS43LjIwLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA
//像這樣的就是被加密的命令
[root@localhost data]# mysqlbinlog --no-defaults --base64-output=decode-rows -v mysql-bin.000002  > /opt/back.txt
//-v 顯示內(nèi)容在界面,--base64解碼器 output輸出 decode-rows 讀取按行讀取
[root@localhost data]# cd /opt
[root@localhost opt]# vim back.txt 
//下面的截圖就是bak.txt中的數(shù)據(jù)信息

MySQL全量、增量備份與恢復(fù)
錯(cuò)誤操作截圖
MySQL全量、增量備份與恢復(fù)
200107 16:57:56 --stop-datetime /指從這個(gè)日志文件開(kāi)始,執(zhí)行到這個(gè)時(shí)間點(diǎn)時(shí)就停止
200107 16:58:46 --start-datetime /指這個(gè)日志文件中,從這個(gè)時(shí)間點(diǎn)開(kāi)始向后面執(zhí)行
先完全備份恢復(fù),source /opt/school.sql

[root@localhost opt]# mysql -uroot -p12341234
mysql> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> drop table info;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from info;
ERROR 1146 (42S02): Table 'school.info' doesn't exist
mysql> show tables;
Empty set (0.00 sec)

mysql> source /opt/school.sql;
Query OK, 0 rows affected (0.00 sec)
。。。。。。

mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| info             |
+------------------+
1 row in set (0.00 sec)

mysql> select * from info;
+----+-------+-------+
| id | name  | score |
+----+-------+-------+
|  1 | stu01 |  88.0 |
|  2 | stu02 |  77.0 |
+----+-------+-------+
2 rows in set (0.00 sec)

mysql>

然后再增量恢復(fù),即時(shí)間上的斷點(diǎn)恢復(fù)

[root@localhost opt]# mysqlbinlog --no-defaults --stop-datetime='2020-01-07 16:57:56' /usr/local/mysql/data/mysql-bin.000002 | mysql -u root -p
Enter password: 

[root@localhost opt]# mysql -uroot -p12341234
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.20-log Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from info;
+----+--------+-------+
| id | name   | score |
+----+--------+-------+
|  1 | stu01  |  88.0 |
|  2 | stu02  |  77.0 |
|  3 | test01 |  66.0 |
+----+--------+-------+
3 rows in set (0.00 sec)

mysql> quit
Bye
[root@localhost opt]# mysqlbinlog --no-defaults --start-datetime='2020-01-07 16:58:46' /usr/local/mysql/data/mysql-bin.000002 | mysql -u root -p
Enter password: 

[root@localhost opt]# mysql -uroot -p12341234
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.20-log Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from info;
+----+--------+-------+
| id | name   | score |
+----+--------+-------+
|  1 | stu01  |  88.0 |
|  2 | stu02  |  77.0 |
|  3 | test01 |  66.0 |
|  4 | test02 |  99.0 |
+----+--------+-------+
4 rows in set (0.00 sec)
//誤操作刪除的stu01 沒(méi)有被刪掉
mysql> 

基于位置的恢復(fù)
錯(cuò)誤操作的日志文件
MySQL全量、增量備份與恢復(fù)

[root@localhost opt]# mysqlbinlog --no-defaults --stop-postion='612' /usr/local/mysql/data/mysql-bin.000002 | mysql -u root -p
mysqlbinlog: [ERROR] unknown variable 'stop-postion=612'
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost opt]# mysqlbinlog --no-defaults --stop-position='612' /usr/local/mysql/data/mysql-bin.000002 | mysql -u root -p
Enter password: 
[root@localhost opt]# mysql -uroot -p12341234
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.20-log Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from info;
+----+--------+-------+
| id | name   | score |
+----+--------+-------+
|  1 | stu01  |  88.0 |
|  2 | stu02  |  77.0 |
|  3 | test01 |  66.0 |
+----+--------+-------+
3 rows in set (0.00 sec)

mysql> quit
Bye
[root@localhost opt]# mysqlbinlog --no-defaults --start-position='716' /usr/local/mysql/data/mysql-bin.000002 | mysql -u root -p
Enter password: 
[root@localhost opt]# mysql -uroot -p12341234mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.20-log Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from info;
+----+--------+-------+
| id | name   | score |
+----+--------+-------+
|  1 | stu01  |  88.0 |
|  2 | stu02  |  77.0 |
|  4 | test02 |  99.0 |
|  3 | test01 |  66.0 |
+----+--------+-------+
4 rows in set (0.00 sec)

mysql> desc info;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(4)       | NO   | PRI | NULL    | auto_increment |
| name  | varchar(10)  | NO   |     | NULL    |                |
| score | decimal(4,1) | NO   |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> quit
Bye
[root@localhost opt]# mysqlbinlog --no-defaults  /usr/local/mysql/data/mysql-bin.000002 | mysql -u root -p
//這個(gè)是增量恢復(fù),將日志文件內(nèi)的所有操作全部執(zhí)行

新聞名稱:MySQL全量、增量備份與恢復(fù)
網(wǎng)站地址:http://vcdvsql.cn/article32/iiposc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營(yíng)銷推廣營(yíng)銷型網(wǎng)站建設(shè)電子商務(wù)網(wǎng)站制作小程序開(kāi)發(fā)網(wǎng)站營(yí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)

小程序開(kāi)發(fā)