日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
MySQL數(shù)據(jù)庫中數(shù)據(jù)被刪除后的恢復

 當數(shù)據(jù)庫被刪除后的恢復方法:

10多年專注成都網站制作,企業(yè)網站制作,個人網站制作服務,為大家分享網站制作知識、方案,網站設計流程、步驟,成功服務上千家企業(yè)。為您提供網站建設,網站制作,網頁設計及定制高端網站建設服務,專注于企業(yè)網站制作,高端網頁制作,對工商代辦等多個領域,擁有豐富建站經驗。

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

[root@CentOS ~]# mysql -u root -p   ← 用root登錄到MySQL服務器
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;  ← 建立一個測試用的數(shù)據(jù)庫test
Query OK, 1 row affected (0.00 sec)

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

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

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

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

mysql> exit  ← 退出MySQL服務器
Bye

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

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

三、接下來,我們再次登錄到MySQL服務器中,刪除剛剛建立的測試用的數(shù)據(jù)庫test,以便于測試數(shù)據(jù)恢復能否成功。

[root@Centos ~]# mysql -u root -p  ← 用root登錄到MySQL服務器
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  ← 連接到測試用的test數(shù)據(jù)庫
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;  ← 刪除測試用數(shù)據(jù)庫test
Query OK, 0 rows affected (0.01 sec)

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

mysql> exit  ← 退出MySQL服務器
Bye

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

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

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

[root@CentOS ~]# mysql -u root -p  ← 用root登錄到MySQL服務器
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;  ← 查看當前存在的數(shù)據(jù)庫
+-------------+
| Database |
+-------------+
| mysql |
| test  |  ← 確認剛剛被刪除的test數(shù)據(jù)庫已經成功被恢復回來!
+------------+
2 rows in set (0.00 sec)

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

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

mysql> exit  ← 退出MySQL服務器
Bye

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


當前文章:MySQL數(shù)據(jù)庫中數(shù)據(jù)被刪除后的恢復
文章起源:http://m.5511xx.com/article/codhehi.html