您好,登錄后才能下訂單哦!
對(duì)于只備份單張表的備份與還原,通過(guò)SELECT命令,可以更快速的達(dá)到備份和恢復(fù)的目的;
以及通過(guò)此方法把一個(gè)數(shù)據(jù)庫(kù)中表的數(shù)據(jù),導(dǎo)入至另一數(shù)據(jù)庫(kù)的表中去。
備份格式:SELECT * INTO OUTFILE '/PATH/TO/somefile.txt'
FROM table_name [WHERE CLAUSE];
#備份table_name表中的[或者備份滿足WHERE語(yǔ)句的數(shù)據(jù)]數(shù)據(jù)至服務(wù)器上保存。
注釋:table_name:需要備份的表 WHERE:滿足的條件,可選項(xiàng)。
/PATH/TO:服務(wù)器上的路徑目錄,且此目錄必須是執(zhí)行SELECT語(yǔ)句的用戶有寫的權(quán)限,
否則無(wú)法備份。
還原格式:LOAD DATA INFILE '/PATH/TO/somefile.txt' INTO TABLE table_name;
注釋:table_name:需要還原的表的名稱,此表必須先在數(shù)據(jù)庫(kù)中存在。
/PATH/TO:備份所存放的路徑
mysql> CREATE TABLE tutor LIKE tutors; #仿照tutors表的框架創(chuàng)建一個(gè)空表tutor
實(shí)例:備份一個(gè)數(shù)據(jù)庫(kù)表的數(shù)據(jù),導(dǎo)入至另一個(gè)數(shù)據(jù)庫(kù)表的數(shù)據(jù);
mysql> USE jiaowu;
Database changed
mysql> SELECT * FROM tutors; #查詢表tutors的信息
+-----+------------------+--------+-----+
| TID | Tname | Gender | Age |
+-----+------------------+--------+-----+
| 1 | HongQigong | M | 93 |
| 2 | HuangYaoshi | M | 63 |
| 3 | HuangRong | F | 46 |
| 4 | HuYidao | M | 65 |
| 5 | XiaoLongnv | F | 28 |
| 6 | HuFei | M | 45 |
| 7 | GuoXiang | F | 32 |
+-----+------------------+--------+-----+
7 rows in set (0.00 sec)
mysql> SELECT * INTO OUTFILE '/tmp/tutor.txt' FROM tutors;
Query OK, 7 rows affected (0.01 sec)
mysql> CREATE TABLE tutor LIKE tutors;
Query OK, 0 rows affected (0.03 sec)
mysql> DESC tutor;
+---------+---------------------------+------+-----+---------+------------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------------------+------+-----+---------+------------------+
| TID | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| Tname | varchar(50) | NO | | NULL | |
| Gender | enum('F','M') | YES | | M | |
| Age | tinyint(3) unsigned | YES | | NULL | |
+---------+---------------------------+------+-----+---------+------------------+
4 rows in set (0.01 sec)
mysql> DESC tutors ;
+---------+---------------------------+------+-----+---------+------------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------------------+------+-----+---------+------------------+
| TID | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| Tname | varchar(50) | NO | | NULL | |
| Gender | enum('F','M') | YES | | M | |
| Age | tinyint(3) unsigned | YES | | NULL | |
+---------+---------------------------+------+-----+---------+------------------+
4 rows in set (0.01 sec)
mysql> DROP TABLE tuors;
Query OK, 0 rows affected (0.03 sec)
mysql> SELECT * FROM tutor; #查詢表tutor的信息
Empty set (0.04 sec) (暫時(shí)無(wú)數(shù)據(jù))
mysql> LOAD DATA INFILE '/tmp/tutor.txt' INTO TABLE tutor;
Query OK, 7 rows affected (0.04 sec)
Records: 7 Deleted: 0 Skipped: 0 Warnings: 0
mysql> SELECT * FROM tutor; #查詢表tutor的信息
+-----+------------------+--------+-----+
| TID | Tname | Gender | Age |
+-----+------------------+--------+-----+
| 1 | HongQigong | M | 93 |
| 2 | HuangYaoshi | M | 63 |
| 3 | HuangRong | F | 46 |
| 4 | HuYidao | M | 65 |
| 5 | XiaoLongnv | F | 28 |
| 6 | HuFei | M | 45 |
| 7 | GuoXiang | F | 32 |
+-----+------------------+--------+-----+
至此通過(guò)SELECT備份還原操作完成。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。