資料庫的備份
1、開啟bin-log
開啟mysql配置檔案 /etc/mysql/my.cnf(這個位置不是固定的,根據你安裝的mysql目錄去找)
放開log_bin這一行
log_bin = /var/log/mysql/mysql-bin.log
隨後重啟mysql 即執行
/etc/init.d/mysql restart
進入資料庫,檢視log_bin開啟狀態
show variables like 『%log_bin%』;
可以看到 log_bin的值是on就表示已經開啟了log-bin
再到/var/log/mysql/目錄下檢視,就已經多了兩個log-bin日誌檔案
mysql-bin.000001
mysql-bin.index
為什麼是兩個呢?
我們開啟mysql-bin.index檔案後看到只有一行資料:
/var/log/mysql/mysql-bin.000001
什麼意思呢?也即是mysql-bin.index這個檔案最終指向了mysql-bin.000001檔案。
2、建立資料庫表並插入資料
drop table if exists xoxo;
create table xoxo (
stuname varchar(10) default null
) engine=innodb default charset=utf8;
insert into xoxo values (『tom』);
insert into xoxo values (『lilei』);
insert into xoxo values (『jimgreen』);
3、刪庫跑路
drop table xoxo;
如果此時沒有對資料庫做備份,且沒有開啟binlog,刪完庫基本就只能坐那哭了。不哭也行,那就是——撒丫子趕緊跑路~
撒丫子跑鴨
4、恢復資料:
先檢視應該從**恢復。
執行命令
/usr/bin/mysqlbinlog –no-defaults mysql-bin.000001 |more
我們可以看到每一次針對資料庫的操作節點。
如at 833
at 934
at 961
我們注意到在刪除資料庫表的下乙個節點是961,那我們恢復資料時的終止節點也需要選這個
恢復:/usr/bin/mysqlbinlog –no-defaults mysql-bin.000001 –stop-position=』961』|mysql -uroot -pfulianzhuren
再進入資料庫看看,資料全部都恢復啦。
oracle資料庫誤處理恢復
今天更新資料的時候忘了加where條件,所以把整個表的資料都更新了,我通過下面的方法恢復了資料 1 在v sqlarea 這檢視裡面找到你操作那條sql的時間 select r.first load time,r.from v sqlarea r order by r.first load time...
oracle資料庫刪除誤刪資料恢復(已經誤刪)
1 select current scn from v database 查詢當前的scn的例如 9048068977098 2 select from ss 表名 as of scn 9048068975698 scn可以 1,直到找到自己有資料的scn 某個scn的前個節點是有資料的。3 sel...
資料庫 資料庫索引
索引是儲存引擎用於快速找到記錄的一種資料結構。索引以檔案的形式儲存在磁碟中。索引可以包含乙個或多個列的值。儲存引擎查詢資料的時候,先在索引中找對應值,然後根據匹配的索引記錄找到對應的資料行。1.b tree索引 2.雜湊索引 myisam和innodb儲存引擎 只支援btree索引,也就是說預設使用...