W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
前文提到,本書的技術(shù)主線是Linux系統(tǒng)的運(yùn)維方向,不會(huì)對(duì)數(shù)據(jù)庫管理系統(tǒng)的操作進(jìn)行深入的講解,因此大家掌握了上面這些基本的數(shù)據(jù)庫操作命令之后就足夠了。下面要講解的是數(shù)據(jù)庫的備份以及恢復(fù),這些知識(shí)比較實(shí)用,希望大家能夠掌握。
mysqldump命令用于備份數(shù)據(jù)庫數(shù)據(jù),格式為“mysqldump [參數(shù)] [數(shù)據(jù)庫名稱]”。其中參數(shù)與mysql命令大致相同,-u參數(shù)用于定義登錄數(shù)據(jù)庫的賬戶名稱,-p參數(shù)代表密碼提示符。下面將linuxprobe數(shù)據(jù)庫中的內(nèi)容導(dǎo)出成一個(gè)文件,并保存到root管理員的家目錄中:
[root@linuxprobe ~]# mysqldump -u root -p linuxprobe > /root/linuxprobeDB.dump
Enter password:此處輸入root管理員在數(shù)據(jù)庫中的密碼
然后進(jìn)入MariaDB數(shù)據(jù)庫管理系統(tǒng),徹底刪除linuxprobe數(shù)據(jù)庫,這樣mybook數(shù)據(jù)表單也將被徹底刪除。然后重新建立linuxprobe數(shù)據(jù)庫:
MariaDB [(none)]> DROP DATABASE linuxprobe;
Query OK, 1 row affected (0.04 sec)
MariaDB [(none)]> SHOW databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.02 sec)
MariaDB [(none)]> CREATE DATABASE linuxprobe;
Query OK, 1 row affected (0.00 sec)
接下來是見證數(shù)據(jù)恢復(fù)效果的時(shí)刻!使用輸入重定向符把剛剛備份的數(shù)據(jù)庫文件導(dǎo)入到mysql命令中,然后執(zhí)行該命令。接下來登錄到MariaDB數(shù)據(jù)庫,就又能看到linuxprobe數(shù)據(jù)庫以及mybook數(shù)據(jù)表單了。數(shù)據(jù)庫恢復(fù)成功!
[root@linuxprobe ~]# mysql -u root -p linuxprobe < /root/linuxprobeDB.dump
Enter password: 此處輸入root管理員在數(shù)據(jù)庫中的密碼值
[root@linuxprobe ~]# mysql -u root -p
Enter password: 此處輸入root管理員在數(shù)據(jù)庫中的密碼值
MariaDB [(none)]> use linuxprobe;
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
MariaDB [linuxprobe]> SHOW tables;
+----------------------+
| Tables_in_linuxprobe |
+----------------------+
| mybook |
+----------------------+
1 row in set (0.05 sec)
MariaDB [linuxprobe]> DESCRIBE mybook;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| name | char(15) | YES | | NULL | |
| price | int(11) | YES | | NULL | |
| pages | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.02 sec)
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: