欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

mysql表刪錯(cuò)怎么回復(fù),mysql誤刪表數(shù)據(jù)恢復(fù)

MySQL刪除表怎么恢復(fù)?

情況1、如果你有該庫的整體備份或?qū)@個(gè)表的單獨(dú)備份,那么也許可以恢復(fù)。可以將最新的備份恢復(fù)到一個(gè)備用的服務(wù)器上,導(dǎo)出那表的內(nèi)容,完成恢復(fù)

創(chuàng)新互聯(lián)2013年至今,先為寧陵等服務(wù)建站,寧陵等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為寧陵企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

情況2、如果沒有任何備份,那就基本沒戲了。一般刪除表的操作是drop table,日志中不會(huì)記錄刪除具體行數(shù)的記錄。表所對應(yīng)目錄下的文件已經(jīng)被刪除(innodb獨(dú)立表空間,單表歸為一文件)。同樣的情況適用于myisam數(shù)據(jù)庫引擎,對應(yīng)的myd/myi/frm文件均被刪除。這不像windows還有垃圾箱,是不可逆的操作

mysql誤刪除一個(gè)表,可以恢復(fù)嗎

1、首先構(gòu)建測試環(huán)境數(shù)據(jù)create table t1(a varchar(10),b varchar(10));insert into t1 values('1','1');insert into t1 values('2','2');commit;。

2、模擬誤修改,將t1表中的b字段更新為錯(cuò)誤數(shù)據(jù) "123456"update t1 set b='123456' where a='1';commit;select * from t1;。

3、將恢復(fù)工具上傳到服務(wù)器并進(jìn)行解壓。unzip binlog2sql-master.zip。

4、得到誤修改時(shí)的binlog文件(show binary logs;),實(shí)驗(yàn)環(huán)境是mysql-bin.000011。

5、通過?binlog2sql.py 腳本的到所有 對表 t1 的修改操作。python binlog2sql.py -hlocalhost -P23307 -ubinlog2sql -p'binlog2sql' -dtest -tt1 --start-file='mysql-bin.000011'。

6、得到了誤刪除的sql的準(zhǔn)確位置在1382-1615之間,使用 _**-B**_ 選項(xiàng)生成回滾sql。python binlog2sql.py -hlocalhost -P23307 -ubinlog2sql -p'binlog2sql' -dtest -tt1 --start-file='mysql-bin.000011' --start-position=1382 --stop-position=1615 -B。

7、執(zhí)行得到的回滾語句進(jìn)行誤操作恢復(fù)。就完成了。

怎么恢復(fù)mysql數(shù)據(jù)表里剛剛刪除的東西

1.第一步,查詢語句:select*fromtable_name;或select*fromtable_namewhere條件,如下圖。

2.第二步,增加語句或插入數(shù)據(jù)insertintotable_name(clus...)values(values...)實(shí)例如圖

3.修改數(shù)據(jù):updatetablenamesetxx=xx,xxx=xxwherexxx=xxxandxxx=xxx,如下圖。

4.第四步,刪除語句deletetable_namewhere條件實(shí)例如圖。

mysql 數(shù)據(jù)庫表誤刪除了 能恢復(fù)嗎

每個(gè) DBA 是不是都有過刪庫的經(jīng)歷?刪庫了沒有備份怎么辦?備份恢復(fù)后無法啟動(dòng)服務(wù)什么情況?表定義損壞數(shù)據(jù)無法讀取怎么辦?

我曾遇到某初創(chuàng)互聯(lián)網(wǎng)企業(yè),因維護(hù)人員不規(guī)范的備份恢復(fù)操作,導(dǎo)致系統(tǒng)表空間文件被初始化,上萬張表無法讀取,花了數(shù)小時(shí)才搶救回來。

當(dāng)你發(fā)現(xiàn)數(shù)據(jù)無法讀取時(shí),也許并非數(shù)據(jù)丟失了,可能是 DBMS 找不到描述數(shù)據(jù)的信息。

背景

先來了解下幾張關(guān)鍵的 InnoDB 數(shù)據(jù)字典表,它們保存了部分表定義信息,在我們恢復(fù)表結(jié)構(gòu)時(shí)需要用到。

SYS_TABLES 描述 InnoDB 表信息CREATE TABLE `SYS_TABLES` (`NAME` varchar(255) NOT NULL DEFAULT '', ?表名`ID` bigint(20) unsigned NOT NULL DEFAULT '0', ?表id`N_COLS` int(10) DEFAULT NULL,`TYPE` int(10) unsigned DEFAULT NULL,`MIX_ID` bigint(20) unsigned DEFAULT NULL,`MIX_LEN` int(10) unsigned DEFAULT NULL,`CLUSTER_NAME` varchar(255) DEFAULT NULL,`SPACE` int(10) unsigned DEFAULT NULL, ? 表空間idPRIMARY KEY (`NAME`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;SYS_INDEXES 描述 InnoDB 索引信息CREATE TABLE `SYS_INDEXES` ( ?`TABLE_ID` bigint(20) unsigned NOT NULL DEFAULT '0', 與sys_tables的id對應(yīng) ?`ID` bigint(20) unsigned NOT NULL DEFAULT '0', ?索引id ?`NAME` varchar(120) DEFAULT NULL, ? ? ? ? 索引名稱 ?`N_FIELDS` int(10) unsigned DEFAULT NULL, 索引包含字段的個(gè)數(shù) ?`TYPE` int(10) unsigned DEFAULT NULL, ?`SPACE` int(10) unsigned DEFAULT NULL, ?存儲(chǔ)索引的表空間id ?`PAGE_NO` int(10) unsigned DEFAULT NULL, ?索引的root page id ?PRIMARY KEY (`TABLE_ID`,`ID`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;SYS_COLUMNS 描述 InnoDB 表的字段信息CREATE TABLE `SYS_COLUMNS` ( ?`TABLE_ID` bigint(20) unsigned NOT NULL, 與sys_tables的id對應(yīng) ?`POS` int(10) unsigned NOT NULL, ? ? 字段相對位置 ?`NAME` varchar(255) DEFAULT NULL, ? ?字段名稱 ?`MTYPE` int(10) unsigned DEFAULT NULL, ?字段編碼 ?`PRTYPE` int(10) unsigned DEFAULT NULL, 字段校驗(yàn)類型 ?`LEN` int(10) unsigned DEFAULT NULL, ?字段字節(jié)長度 ?`PREC` int(10) unsigned DEFAULT NULL, 字段精度 ?PRIMARY KEY (`TABLE_ID`,`POS`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;SYS_FIELDS 描述全部索引的字段列CREATE TABLE `SYS_FIELDS` ( ?`INDEX_ID` bigint(20) unsigned NOT NULL, ?`POS` int(10) unsigned NOT NULL, ?`COL_NAME` varchar(255) DEFAULT NULL, ?PRIMARY KEY (`INDEX_ID`,`POS`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;./storage/innobase/include/dict0boot.h 文件定義了每個(gè)字典表的 index id,對應(yīng) id 的 page 中存儲(chǔ)著字典表的數(shù)據(jù)。

這里我們需要借助 undrop-for-innodb 工具恢復(fù)數(shù)據(jù),它能讀取表空間信息得到 page,將數(shù)據(jù)從 page 中提取出來。

# wget yum install -y gcc flex bison# make# make sys_parser

# ./sys_parser 讀取表結(jié)構(gòu)信息

sys_parser [-h] [-u] [-p] [-d] databases/table

stream_parser 讀取 InnoDB page 從 ibdata1 或 ibd 或分區(qū)表

# ./stream_parserYou must specify file with -f optionUsage: ./stream_parser -f innodb_datafile [-T N:M] [-s size] [-t size] [-V|-g] ?Where: ? ?-h ? ? ? ? - Print this help ? ?-V or -g ? - Print debug information ? ?-s size ? ?- Amount of memory used for disk cache (allowed examples 1G 10M). Default 100M ? ?-T ? ? ? ? - retrieves only pages with index id = NM (N - high word, M - low word of id) ? ?-t size ? ?- Size of InnoDB tablespace to scan. Use it only if the parser can't determine it by himself.

c_parser 從 innodb page 中讀取記錄保存到文件

# ./c_parserError: Usage: ./c_parser -4|-5|-6 [-dDV] -f InnoDB page or dir -t table.sql [-T N:M] [-b external pages directory] ?Where ? ?-f InnoDB page(s) -- InnoDB page or directory with pages(all pages should have same index_id) ? ?-t table.sql -- CREATE statement of a table ? ?-o file -- Save dump in this file. Otherwise print to stdout ? ?-l file -- Save SQL statements in this file. Otherwise print to stderr ? ?-h ?-- Print this help ? ?-d ?-- Process only those pages which potentially could have deleted records (default = NO) ? ?-D ?-- Recover deleted rows only (default = NO) ? ?-U ?-- Recover UNdeleted rows only (default = YES) ? ?-V ?-- Verbose mode (lots of debug information) ? ?-4 ?-- innodb_datafile is in REDUNDANT format ? ?-5 ?-- innodb_datafile is in COMPACT format ? ?-6 ?-- innodb_datafile is in MySQL 5.6 format ? ?-T ?-- retrieves only pages with index id = NM (N - high word, M - low word of id) ? ?-b dir -- Directory where external pages can be found. Usually it is pages-XXX/FIL_PAGE_TYPE_BLOB/ ? ?-i file -- Read external pages at their offsets from file. ? ?-p prefix -- Use prefix for a directory name in LOAD DATA INFILE command

接下來,我們演示場景的幾種數(shù)據(jù)恢復(fù)場景。

場景1:drop table

是否啟用了 innodb_file_per_table 其恢復(fù)方法有所差異,當(dāng)發(fā)生誤刪表時(shí),應(yīng)盡快停止MySQL服務(wù),不要啟動(dòng)。若 innodb_file_per_table=ON,最好只讀方式重新掛載文件系統(tǒng),防止其他進(jìn)程寫入數(shù)據(jù)覆蓋之前塊設(shè)備的數(shù)據(jù)。

如果評估記錄是否被覆蓋,可以表中某些記錄的作為關(guān)鍵字看是否能從 ibdata1 中篩選出。

#?grep WOODYHOFFMAN ibdata1

Binary file ibdata1 matches

也可以使用 bvi(適用于較小文件)或 hexdump -C(適用于較大文件)工具

以表 sakila.actor 為例CREATE TABLE `actor` (`actor_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,`first_name` varchar(45) NOT NULL,`last_name` varchar(45) NOT NULL,`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`actor_id`),KEY `idx_actor_last_name` (`last_name`)) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8

首先恢復(fù)表結(jié)構(gòu)信息1. 解析系統(tǒng)表空間獲取 page 信息

./stream_parser -f /var/lib/mysql/ibdata1

2. 新建一個(gè) schema,把系統(tǒng)字典表的 DDL 導(dǎo)入

cat dictionary/SYS_* | mysql recovered

3. 創(chuàng)建恢復(fù)目錄

mkdir -p dumps/default

4. 解析系統(tǒng)表空間包含的字典表信息,

./c_parser -4f pages-ibdata1/FIL_PAGE_INDEX/0000000000000001.page -t dictionary/SYS_TABLES.sql dumps/default/SYS_TABLES 2 dumps/default/SYS_TABLES.sql./c_parser -4f pages-ibdata1/FIL_PAGE_INDEX/0000000000000002.page -t dictionary/SYS_COLUMNS.sql dumps/default/SYS_COLUMNS 2 dumps/default/SYS_COLUMNS.sql./c_parser -4f pages-ibdata1/FIL_PAGE_INDEX/0000000000000003.page -t dictionary/SYS_INDEXES.sql dumps/default/SYS_INDEXES 2 dumps/default/SYS_INDEXES.sql./c_parser -4f pages-ibdata1/FIL_PAGE_INDEX/0000000000000004.page -t dictionary/SYS_FIELDS.sql dumps/default/SYS_FIELDS 2 dumps/default/SYS_FIELDS.sql

5. 導(dǎo)入恢復(fù)的數(shù)據(jù)字典

cat dumps/default/*.sql | mysql recovered

6. 讀取恢復(fù)后的表結(jié)構(gòu)信息

./sys_parser -pmsandbox -d recovered sakila/actor

由于 5.x 版本 innodb 引擎并非完整記錄表結(jié)構(gòu)信息,會(huì)丟失 AUTO_INCREMENT 屬性、二級索引和外鍵約束, DECIMAL 精度等信息。

若是 mysql 5.5 版本 frm 文件被從系統(tǒng)刪除,在原目錄下 touch 與原表名相同的 frm 文件,還能讀取表結(jié)構(gòu)信息和數(shù)據(jù)。若只有 frm 文件,想要獲得表結(jié)構(gòu)信息,可使用 mysqlfrm --diagnostic /path/to/xxx.frm,連接 mysql 會(huì)顯示字符集信息。

innodb_file_per_table=OFF

因?yàn)槭枪蚕肀砜臻g模式,數(shù)據(jù)頁都存儲(chǔ)在 ibdata1,可以從 ibdata1 文件中提取數(shù)據(jù)。

1. 獲取表的 table id,sys_table 存有表的 table id,sys_table 表 index id 是1,所以從0000000000000001.page 獲取表 id./c_parser -4Df pages-ibdata1/FIL_PAGE_INDEX/0000000000000001.page -t dictionary/SYS_TABLES.sql | grep sakila/actor000000000B28 ?2A000001430D4D ?SYS_TABLES ?"sakila/actor" ?158 ?4 ?1 0 ? 0 ? "" ?0000000000B28 ?2A000001430D4D ?SYS_TABLES ?"sakila/actor" ?158 ?4 ?1 0 ? 0 ? "" ?0

2. 利用 table id 獲取表的主鍵 id,sys_indexes 存有表索引信息,innodb 索引組織表,找到主鍵 id 即找到數(shù)據(jù),sys_indexes 的 index id 是3,所以從0000000000000003.page 獲取主鍵 id

./c_parser -4Df pages-ibdata1/FIL_PAGE_INDEX/0000000000000003.page -t dictionary/SYS_INDEXES.sql | grep 158000000000B28 ? ?2A000001430BCA ?SYS_INDEXES ? ? 158 ? ? 376 ? ? "PRIMARY" ? ? ? 1 ? ? ? 3 ? ? ? 0 ? ? ? 4294967295000000000B28 ? ?2A000001430C3C ?SYS_INDEXES ? ? 158 ? ? 377 ? ? "idx_actor_last_name" ? ? ? ?1 ? ? ? 0 ? ? ? 0 ? ? ? 4294967295000000000B28 ? ?2A000001430BCA ?SYS_INDEXES ? ? 158 ? ? 376 ? ? "PRIMARY" ? ? ? 1 ? ? ? 3 ? ? ? 0 ? ? ? 4294967295000000000B28 ? ?2A000001430C3C ?SYS_INDEXES ? ? 158 ? ? 377 ? ? "idx_actor_last_name" ? ? ? ?1 ? ? ? 0 ? ? ? 0 ? ? ? 4294967295

3. 知道了主鍵 id,就可以從對應(yīng) page 中提取表數(shù)據(jù),并生成 sql 文件。

./c_parser -4f pages-ibdata1/FIL_PAGE_INDEX/0000000000000376.page -t sakila/actor.sql dumps/default/actor 2 dumps/default/actor_load.sql

4. 最后導(dǎo)入恢復(fù)的數(shù)據(jù)

cat dumps/default/*.sql | mysql sakila

更多詳細(xì)情況點(diǎn)擊網(wǎng)頁鏈接

請點(diǎn)擊輸入圖片描述

mysql刪除數(shù)據(jù)庫后怎么恢復(fù)

使用mysql中的日志功能。

首先:將最近的二進(jìn)制類型的日志文件存成文本文件導(dǎo)出,命令如下:

mysqlbinlog

F:/wamp/mysql-bin.000045

F:/test.txt

其次:打開保存的txt文件,文件格式如下:

其中at

1099代表第1099個(gè)命令(姑且這么記),查詢這些命令,看看需要回復(fù)的命令在什么地方,然后執(zhí)行命令。

最后:執(zhí)行回復(fù)命令,如下:

mysqlbinlog

--start-position="123"

--stop-position="531"

F:/wamp/mysql-bin.000045

F:/test.txt

|

mysql

-uroot

-p

這樣就可以完成數(shù)據(jù)庫的回復(fù)了!!!

mysql的數(shù)據(jù)刪除后怎么恢復(fù)

如果你要恢復(fù)的數(shù)據(jù)庫是包含授權(quán)表的mysql數(shù)據(jù)庫,您將需要使用--skip贈(zèng)款-tables選項(xiàng)來運(yùn)行服務(wù)器恢復(fù)整個(gè)數(shù)據(jù)庫

- 首先,。否則,服務(wù)器會(huì)抱怨不能找到授權(quán)表。恢復(fù)表后,執(zhí)行mysqladmin沖水privileges告訴服務(wù)器裝載授權(quán)表,并用它們來啟動(dòng)。數(shù)據(jù)庫目錄到其他地方的原始內(nèi)容

復(fù)制。例如,您可以使用它們在以后的事后分析檢查表(驗(yàn)尸)的崩潰。

酒店與最新的數(shù)據(jù)庫備份文件重新加載。如果您打算使用mysqldump的所加載的文件,則需要輸入它們作為mysql的。如果您打算使用從數(shù)據(jù)庫文件直接拷貝(例如,使用tar或CP),它會(huì)復(fù)制他們直接回?cái)?shù)據(jù)庫目錄中。然而,在這種情況下,你應(yīng)該在關(guān)閉之前,該服務(wù)器復(fù)制這些文件,然后重新啟動(dòng)它。在備份過程中

重做日志,然后查詢更新數(shù)據(jù)庫表中。對于所有可用的更新日志,你可以使用它作為mysql的輸入。指定--one-database選項(xiàng),因此MySQL只是要還原的數(shù)據(jù)庫執(zhí)行查詢。如果你意識到有必要使用所有的更新日志文件,可以使用包含以下命令日志的目錄:

%LS-TRL更新(0-9)* | xargs的貓| mysql--。一個(gè)數(shù)據(jù)庫DB_NAME

ls命令生成一個(gè)單獨(dú)的日志文件更新列表,更新日志文件根據(jù)服務(wù)器(你知道,如果你其中的任何文件,排序順序生成的順序進(jìn)行排序會(huì)發(fā)生變化,這將導(dǎo)致在更新日志中以錯(cuò)誤的順序使用)。有限公司您可能需要使用一些更新日志。例如,如果日志,因?yàn)槊鹵pdate.392備份,pdate.393等產(chǎn)生的,可以在命令重新運(yùn)行它們:

%的mysql - 一個(gè)數(shù)據(jù)庫DB_NAME 錄入。 392

%的mysql - 一個(gè)數(shù)據(jù)庫DB_NAME updata.393 ...

如果您正在運(yùn)行的恢復(fù),并打算使用更新日志恢復(fù)由于失誤降數(shù)據(jù)的基礎(chǔ)上,DROPTABLE或DELETE語句和丟失的信息時(shí),一定要在開始更新日志刪除這些語句。

恢復(fù)單個(gè)表

恢復(fù)單個(gè)表是非常困難的。如果是的mysqldump備份文件生成的,它只是不包含數(shù)據(jù),您需要一個(gè)表,你需要提取的相關(guān)線路,并利用它們作為mysql的輸入,這部分比較容易。困難的是,提取在該表的更新日志中使用的片段。你會(huì)發(fā)現(xiàn):mysql_find_rows工具在這方面有所幫助,它可以提取多行從更新日志查詢。另一種可能性是使用另一臺(tái)服務(wù)器

恢復(fù)整個(gè)數(shù)據(jù)庫,然后將該文件復(fù)制到表的原始數(shù)據(jù)庫。這其實(shí)很容易!當(dāng)文件被復(fù)制回?cái)?shù)據(jù)庫目錄,確保原始數(shù)據(jù)庫服務(wù)器關(guān)閉。

分享文章:mysql表刪錯(cuò)怎么回復(fù),mysql誤刪表數(shù)據(jù)恢復(fù)
當(dāng)前路徑:http://chinadenli.net/article1/dsipoid.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管建站公司品牌網(wǎng)站建設(shè)動(dòng)態(tài)網(wǎng)站網(wǎng)站設(shè)計(jì)公司企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)