自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

MySQL數(shù)據(jù)庫(kù)中數(shù)據(jù)被刪除后的恢復(fù)

數(shù)據(jù)庫(kù) MySQL
MySQL數(shù)據(jù)庫(kù)操作過(guò)程中可能會(huì)出現(xiàn)誤刪的情況,鑒于數(shù)據(jù)庫(kù)中數(shù)據(jù)都是非常重要的,所以要將誤刪的數(shù)據(jù)庫(kù)恢復(fù),便于之后的工作的繼續(xù)進(jìn)行。

 當(dāng)數(shù)據(jù)庫(kù)被刪除后的恢復(fù)方法:

一、首先建立一個(gè)測(cè)試用的數(shù)據(jù)庫(kù)。

[root@CentOS ~]# mysql -u root -p   ← 用root登錄到MySQL服務(wù)器
Enter password:  ← 輸入MySQL的root用戶密碼
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database test;  ← 建立一個(gè)測(cè)試用的數(shù)據(jù)庫(kù)test
Query OK, 1 row affected (0.00 sec)

mysql> use test  ← 連接到這個(gè)數(shù)據(jù)庫(kù)
Database changed

mysql> create table test(num int, name varchar(50));  ← 在數(shù)據(jù)庫(kù)中建立一個(gè)表
Query OK, 0 rows affected (0.07 sec)

mysql> insert into test values(1,'Hello,CentOS');  ← 插入一個(gè)值到這個(gè)表(這里以“Hello,CentOS”為例)
Query OK, 1 row affected (0.02 sec)

mysql> select * from test;  ← 查看數(shù)據(jù)庫(kù)中的內(nèi)容
+------+-----------------+
| num | name |
+------+-----------------+
|1  | Hello,Centos |  ← 確認(rèn)剛剛插入到表中的值的存在
+------+------------------+
1 row in set (0.01 sec)

mysql> exit  ← 退出MySQL服務(wù)器
Bye

二、然后,運(yùn)行剛才建立的數(shù)據(jù)庫(kù)備份腳本,備份剛剛建立的測(cè)試用的數(shù)據(jù)庫(kù)。

[root@sample ~]# cd ← 回到腳本所在的root用戶的根目錄
[root@sample ~]# ./mysql-backup.sh  ← 運(yùn)行腳本進(jìn)行數(shù)據(jù)庫(kù)備份

三、接下來(lái),我們?cè)俅蔚卿浀組ySQL服務(wù)器中,刪除剛剛建立的測(cè)試用的數(shù)據(jù)庫(kù)test,以便于測(cè)試數(shù)據(jù)恢復(fù)能否成功。

[root@Centos ~]# mysql -u root -p  ← 用root登錄到MySQL服務(wù)器
Enter password:  ← 輸入MySQL的root用戶密碼
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use test  ← 連接到測(cè)試用的test數(shù)據(jù)庫(kù)
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 test;  ← 刪除數(shù)據(jù)中的表
Query OK, 0 rows affected (0.04 sec)

mysql> drop database test;  ← 刪除測(cè)試用數(shù)據(jù)庫(kù)test
Query OK, 0 rows affected (0.01 sec)

mysql> show databases;
+---------------+
| Database |
+---------------+
| mysql |  ← 確認(rèn)測(cè)試用的test數(shù)據(jù)庫(kù)已不存在、已被刪除
+---------------+
1 row in set (0.01 sec)

mysql> exit  ← 退出MySQL服務(wù)器
Bye

以上,我們就等于模擬了數(shù)據(jù)庫(kù)被破壞的過(guò)程。接下來(lái),是數(shù)據(jù)庫(kù)被“破壞”后,用備份進(jìn)行恢復(fù)的方法。

[root@Centos ~]# /bin/cp -Rf /backup/mysql/test/ /var/lib/mysql/  ← 復(fù)制備份的數(shù)據(jù)庫(kù)test到相應(yīng)目錄
[root@Centos ~]# chown -R mysql:mysql /var/lib/mysql/test/  ← 改變數(shù)據(jù)庫(kù)test的歸屬為mysql
[root@Centos ~]# chmod 700 /var/lib/mysql/test/  ← 改變數(shù)據(jù)庫(kù)目錄屬性為700
[root@Centos ~]# chmod 660 /var/lib/mysql/test/*  ← 改變數(shù)據(jù)庫(kù)中數(shù)據(jù)的屬性為660

然后,再次登錄到MySQL服務(wù)器上,看是否已經(jīng)成功恢復(fù)了數(shù)據(jù)庫(kù)。

[root@CentOS ~]# mysql -u root -p  ← 用root登錄到MySQL服務(wù)器
Enter password:  ← 輸入MySQL的root用戶密碼
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;  ← 查看當(dāng)前存在的數(shù)據(jù)庫(kù)
+-------------+
| Database |
+-------------+
| mysql |
| test  |  ← 確認(rèn)剛剛被刪除的test數(shù)據(jù)庫(kù)已經(jīng)成功被恢復(fù)回來(lái)!
+------------+
2 rows in set (0.00 sec)

mysql> use test  ← 連接到test數(shù)據(jù)庫(kù)
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;  ← 查看test數(shù)據(jù)庫(kù)中存在的表
+-------------------+
| Tables_in_test |
+-------------------+
| test  |
+-------------------+
1 row in set (0.00 sec)

mysql> select * from test;  ← 查看數(shù)據(jù)庫(kù)中的內(nèi)容
+------+---------------------+
| num | name  |
+------+---------------------+
| 1 | Hello,CentOS |  ← 確認(rèn)數(shù)據(jù)表中的內(nèi)容與刪除前定義的“Hello,CentOS”一樣!
+------+---------------------+
1 row in set (0.01 sec)

mysql> exit  ← 退出MySQL服務(wù)器
Bye

以上結(jié)果表示,數(shù)據(jù)庫(kù)被刪除后,用備份后的數(shù)據(jù)庫(kù)成功的將數(shù)據(jù)恢復(fù)到了刪除前的狀態(tài)。

【編輯推薦】

  1. MySQL數(shù)據(jù)庫(kù)的自動(dòng)備份
  2. Mysql數(shù)據(jù)庫(kù)服務(wù)器安裝與配置
  3. MysQL數(shù)據(jù)庫(kù)的技術(shù)特點(diǎn)點(diǎn)評(píng)

 

責(zé)任編輯:迎迎 來(lái)源: 中國(guó)站長(zhǎng)站綜合
相關(guān)推薦

2018-04-28 15:28:44

數(shù)據(jù)庫(kù)MySQL誤刪除

2017-04-01 18:30:47

MySQL誤刪除數(shù)據(jù)庫(kù)

2019-08-20 14:02:07

MongoDB數(shù)據(jù)庫(kù)恢復(fù)數(shù)據(jù)

2009-06-29 08:52:04

Linux

2010-06-09 15:40:59

MySQL數(shù)據(jù)庫(kù)文件

2021-05-24 09:08:50

數(shù)據(jù)庫(kù)工具技術(shù)

2010-04-21 12:13:44

Oracle數(shù)據(jù)庫(kù)

2011-03-30 14:19:56

MySQL數(shù)據(jù)庫(kù)修改恢復(fù)

2010-05-21 10:01:11

MySQL數(shù)據(jù)庫(kù)

2011-05-24 14:13:20

Oracle數(shù)據(jù)庫(kù)

2010-11-15 15:34:30

ORACLE數(shù)據(jù)庫(kù)恢復(fù)

2010-06-04 18:45:00

MySQL數(shù)據(jù)庫(kù)

2011-08-01 14:50:10

日志挖掘數(shù)據(jù)庫(kù)

2010-08-16 16:23:56

DB2卸載

2010-04-13 10:15:17

Oracle數(shù)據(jù)庫(kù)

2010-05-28 10:03:33

MySQL數(shù)據(jù)庫(kù)

2018-10-10 14:47:39

2011-05-18 10:49:53

Oralce數(shù)據(jù)庫(kù)

2011-03-24 17:49:47

數(shù)據(jù)庫(kù)恢復(fù)

2011-03-24 09:45:34

SQL Server數(shù)恢復(fù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)