




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第13章備份和恢復(fù)《MySQL數(shù)據(jù)庫(kù)應(yīng)用教程》劉瑞新主編配套資源目錄第13章備份和恢復(fù)13.1備份與恢復(fù)概述13.2使用mysqldump命令備份數(shù)據(jù)13.3數(shù)據(jù)的恢復(fù)13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.5表記錄的導(dǎo)出與導(dǎo)入13.1.1數(shù)據(jù)備份的原因1.系統(tǒng)故障2.事務(wù)故障3.介質(zhì)故障4.其他災(zāi)害13.1備份與恢復(fù)概述13.1.2數(shù)據(jù)庫(kù)備份的分類1.按備份時(shí)服務(wù)器是否在線劃分(1)熱備份(2)溫備份(3)冷備份13.1備份與恢復(fù)概述2.按備份的內(nèi)容劃分(1)邏輯備份(2)物理備份13.1備份與恢復(fù)概述3.按備份涉及的數(shù)據(jù)范圍劃分(1)完整備份(2)增量備份(3)差異備份13.1備份與恢復(fù)概述13.1.3備份的周期和頻率13.1.4數(shù)據(jù)恢復(fù)的方法13.1備份與恢復(fù)概述13.2.1備份數(shù)據(jù)庫(kù)或表mysqldump[-h[hostname]]-uusername-p[password]db_name[tb_name1tb_name2...]>filename.sql13.2使用mysqldump命令備份數(shù)據(jù)【例13-1】使用mysqldump命令,備份studentinfo數(shù)據(jù)庫(kù)中的所有表,備份文件studentinfo.sql存儲(chǔ)在d:/db文件夾中。1)2)C:\Users\Administrator>mysqldump-uroot-pstudentinfo>d:/db/studentinfo.sql13.2使用mysqldump命令備份數(shù)據(jù)【例13-2】使用mysqldump命令備份studentinfo數(shù)據(jù)庫(kù)中的class、student表,備份文件studentinfo_class_student.sql存儲(chǔ)在D:/db文件夾中。C:\Users\Administrator>mysqldump-uroot-p123456studentinfoclassstudent>d:/db/studentinfo_class_student.sqlmysqldump:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure.13.2使用mysqldump命令備份數(shù)據(jù)13.2.2查看備份文件13.2使用mysqldump命令備份數(shù)據(jù)13.2.3使用mysqldump命令備份多個(gè)數(shù)據(jù)庫(kù)mysqldump-uusermame-p[password]--databasesdb_name1[db_name2...]>filename.sql【例13-3】使用mysqldump命令備份數(shù)據(jù)庫(kù)studentinfo。C:\Users\Administrator>mysqldump-uroot-p--databasesstudentinfo>d:/db/studentinfo2.sqlEnterpassword:******13.2使用mysqldump命令備份數(shù)據(jù)【例13-3】使用mysqldump命令備份數(shù)據(jù)庫(kù)studentinfo。C:\Users\Administrator>mysqldump-uroot-p--databasesstudentinfo>d:/db/studentinfo2.sqlEnterpassword:******13.2使用mysqldump命令備份數(shù)據(jù)13.2使用mysqldump命令備份數(shù)據(jù)13.2.4使用mysqldump命令備份服務(wù)器上的所有數(shù)據(jù)庫(kù)mysgldump-uusername-p--all-databases>filename.sql【例13-4】使用mysqldump命令備份MySQL服務(wù)器上的所有數(shù)據(jù)庫(kù)。在“命令提示符”窗口中輸入下面?zhèn)浞莘?wù)器上全部數(shù)據(jù)庫(kù)的命令:C:\Users\Administrator>mysqldump-uroot-p--all-databases>d:/db/all_mysql.sqlEnterpassword:******13.2使用mysqldump命令備份數(shù)據(jù)11.3.1使用mysql命令恢復(fù)數(shù)據(jù)使用mysgl命令恢復(fù)表mysql-uusername-pdb_name<filename.sql【例13-5】使用mysql命令恢復(fù)studentinfo數(shù)據(jù)庫(kù)中的class、student表,備份文件是例13-2中使用mysqldump命令備份的腳本文件studentinfo_class_student.sql,存儲(chǔ)在D:/db文件夾中。C:\Users\Administrator>mysql-uroot-pstudentinfo<d:/db/studentinfo_class_student.sqlEnterpassword:******13.3數(shù)據(jù)的恢復(fù)2.使用mysql命令還原單個(gè)數(shù)據(jù)庫(kù)或者多個(gè)數(shù)據(jù)庫(kù)mysql-uusername-p<filename.sql【例13-6】使用mysql命令還原studentinfo數(shù)據(jù)庫(kù),備份文件是例13-3中使用mysqldump命令備份的腳本文件studentinfo2.sql,存儲(chǔ)在D:/db文件夾中。C:\Users\Administrator>mysql-uroot-pEnterpassword:******mysql>DROPDATABASEstudentinfo;mysql>QUIT13.3數(shù)據(jù)的恢復(fù)4)C:\Users\Administrator>mysql-uroot-p<d:/db/studentinfo2.sqlEnterpassword:******5)C:\Users\Administrator>mysql-uroot-pEnterpassword:******6)mysql>SHOWDATABASES;7)mysql>USEstudentinfo;mysql>SHOWTABLES;8)mysql>SELECT*FROMstudent;13.3數(shù)據(jù)的恢復(fù)11.3.2使用source語(yǔ)句恢復(fù)數(shù)據(jù)SOUCEfilename.sql1.恢復(fù)指定數(shù)據(jù)庫(kù)中的表【例13-7】在studentinfo數(shù)據(jù)庫(kù)中,刪除student表中的所有記錄。用source語(yǔ)句恢復(fù)該數(shù)據(jù)庫(kù)中student表中被刪除的記錄。1)C:\Users\Administrator>mysqldump-uroot-pstudentinfostudent>d:/db/studentinfo_student.sqlEnterpassword:******2)C:\Users\Administrator>mysql-uroot-pEnterpassword:******13.3數(shù)據(jù)的恢復(fù)3)mysql>USEstudentinfo;Databasechangedmysql>SELECT*FROMstudent;4)mysql>DELETEFROMstudent;QueryOK,11rowsaffected(0.01sec)mysql>SELECT*FROMstudent;Emptyset(0.00sec)mysql>DROPTABLEstudent;QueryOK,0rowsaffected(0.03sec)mysql>SHOWTABLES;13.3數(shù)據(jù)的恢復(fù)5)mysql>SOURCEd:/db/studentinfo_student.sql;QueryOK,0rowsaffected(0.00sec)…QueryOK,0rowsaffected(0.00sec)QueryOK,11rowsaffected(0.01sec)Records:11Duplicates:0Warnings:0…QueryOK,0rowsaffected(0.00sec)6)mysql>SELECT*FROMstudent;13.3數(shù)據(jù)的恢復(fù)2.恢復(fù)指定數(shù)據(jù)庫(kù)中的所有表【例13-8】用source語(yǔ)句將例13-1中生成的備份文件studentinfo.sql恢復(fù)到studentinfo數(shù)據(jù)庫(kù)中。操作步驟如下。1)C:\Users\Administrator>mysql-uroot-pEnterpassword:******2)mysql>DROPDATABASEstudentinfo;QueryOK,5rowsaffected(0.07sec)13.3數(shù)據(jù)的恢復(fù)2)mysql>CREATEDATABASEstudentinfo;QueryOK,1rowaffected(0.01sec)mysql>USEstudentinfo;Databasechanged3)mysql>SOURCEd:/db/studentinfo.sql;4)mysql>USEstudentinfo;Databasechangedmysql>SELECT*FROMstudent;13.3數(shù)據(jù)的恢復(fù)1.備份數(shù)據(jù)庫(kù)【例13-9】備份studentinfo數(shù)據(jù)庫(kù)。13.4使用NavicatforMySQL菜單方式備份與恢復(fù)數(shù)據(jù)13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.4其他備份與恢復(fù)數(shù)據(jù)的方法2.恢復(fù)數(shù)據(jù)庫(kù)【例13-10】恢復(fù)studentinfo數(shù)據(jù)庫(kù)。13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.4其他備份與恢復(fù)數(shù)據(jù)的方法3.提取SQL【例13-11】從備份文件中提取SQL腳本文件。13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.4其他備份與恢復(fù)數(shù)據(jù)的方法4.轉(zhuǎn)儲(chǔ)SQL文件【例13-12】生成studentinfo數(shù)據(jù)庫(kù)的備份腳本文件。13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.4其他備份與恢復(fù)數(shù)據(jù)的方法5.運(yùn)行SQL文件【例13-13】從腳本文件恢復(fù)studentinfo數(shù)據(jù)庫(kù)。13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.5表記錄的導(dǎo)出與導(dǎo)入13.5.1使用SELECT...INTOOUTFILE語(yǔ)句導(dǎo)出文本文件SELECT{*|column1[,column2...]}FROMtb_name[WHEREconditions]INTOOUTFILE'filename'[options];[FIELDS[TERMIATEDBY'string'][[OPTIONALLY]ENCLOSEDBY'CHAR'][ESCAPEDBY'CHAR']][LINES[STARTINGBY'string'][TERMINATEDBY'string']]13.4其他備份與恢復(fù)數(shù)據(jù)的方法【例13-14】把studentinfo數(shù)據(jù)庫(kù)中的student表中的所有記錄導(dǎo)出到在服務(wù)器上的默認(rèn)文件夾C:/ProgramData/MySQL/MySQLServer8.0/Uploads/st2022-1.txt。USEstudentinfo;SELECT*FROMstudentINTOOUTFILE'C:/ProgramData/MySQL/MySQLServer8.0/Uploads/st2022-1.txt';13.4其他備份與恢復(fù)數(shù)據(jù)的方法【例13-15】在studentinfo數(shù)據(jù)庫(kù)中,導(dǎo)出student表中的所有女生記錄,保存到在服務(wù)器上的默認(rèn)文件夾C:/ProgramData/MySQL/MySQLServer8.0/Uploads/st2022-3.txt。其中,列值之間用“,”分隔,字符型數(shù)據(jù)用雙引號(hào)括起來(lái),每條記錄以“<”開(kāi)頭,以“>\r\n”結(jié)尾。SQL語(yǔ)句如下:SELECTStudentID,StudentName,Sex,Birthday,Address,100FROMstudentWHERESex='女'ORDERBYStudentIDINTOOUTFILE'C:/ProgramData/MySQL/MySQLServer8.0/Uploads/st2022-3.txt'CHARACTERSETutf8mb4FIELDSTERMINATEDBY','OPTIONALLYENCLOSEDBY'"'#'"'單引號(hào)中是1個(gè)雙引號(hào)
LINESSTARTINGBY'<'TERMINATEDBY'>\r\n';13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.5.2使用LOADDATAINFILE語(yǔ)句導(dǎo)入文本文件LOADDATA[{LOW_PRIORITY|CONCURRENT}]INFILE'filename'[{REPLACE|IGNORE}]INTOTABLEtb_name[options][IGNOREnLINES][({column|UserVariables}],…)][SETcolumn=expression,….)];13.4其他備份與恢復(fù)數(shù)據(jù)的方法【例13-16】把服務(wù)器上C:/ProgramData/MySQL/MySQLServer8.0/Uploads/st2022-1.txt文件導(dǎo)入到studentinfo數(shù)據(jù)庫(kù)中的student表中。在NavicatforMySQL中打開(kāi)studentinfo數(shù)據(jù)庫(kù),在查詢窗格中運(yùn)行下面SQL語(yǔ)句:LOADDATAINFILE'C:/ProgramData/MySQL/MySQLServer8.0/Uploads/st2022-1.txt'REPLACEINTOTABLEstudent;13.4其他備份與恢復(fù)數(shù)據(jù)的方法【例13-17】在studentinfo數(shù)據(jù)庫(kù)中創(chuàng)建一張新表student3,使用LOADDATAINFILE語(yǔ)句將C:/ProgramData/MySQL/MySQLServer8.0/Uploads/st2022-3.txt中的記錄導(dǎo)入到student3表中。1)CREATETABLEstudentinfo.student3(StudentIDCHAR(12)PRIMARYKEY,StudentNameVARCHAR(20)NOTNULL,SexCHAR(2)NOTNULL,BirthdayDATENULLDEFAULTNULL,AddressVARCHAR(30),NumberINT)ENGINE=InnoDBCHARACTERSET=utf8mb4;13.4其他備份與恢復(fù)數(shù)據(jù)的方法2)LOADDATAINFILE'C:/ProgramData/MySQL/MySQLServer8.0/Uploads/st2022-3.txt'INTOTABLEstudentinfo.student3CHARACTERSETutf8mb4FIELDSTERMINATEDBY','OPTIONALLYENCLOSEDBY'"'#'"
LINESSTARTINGBY'<'TERMINATEDBY'>\r\n';3)SELECT*FROMstudentinfo.student3;13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.5.3設(shè)置導(dǎo)出文本文件的路徑1)SHOWVARIABLESLIKE'%secure%';13.4其他備份與恢復(fù)數(shù)據(jù)的方法13.4其他備份與恢復(fù)數(shù)據(jù)的方法以管理員身份用記事本打開(kāi)my.ini文件,查找到secure-file-privsecure-file-priv="d:/db"13.4其他備份與恢復(fù)數(shù)據(jù)的方法
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 山西傳媒學(xué)院《學(xué)術(shù)規(guī)范及論文寫(xiě)作技巧》2023-2024學(xué)年第二學(xué)期期末試卷
- 大同師范高等專科學(xué)?!毒扑{(diào)制與酒吧管理》2023-2024學(xué)年第二學(xué)期期末試卷
- 南充職業(yè)技術(shù)學(xué)院《食品添加劑實(shí)驗(yàn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 長(zhǎng)春職業(yè)技術(shù)學(xué)院《數(shù)據(jù)庫(kù)原理》2023-2024學(xué)年第二學(xué)期期末試卷
- 紅河衛(wèi)生職業(yè)學(xué)院《基礎(chǔ)實(shí)踐》2023-2024學(xué)年第二學(xué)期期末試卷
- 哈爾濱體育學(xué)院《現(xiàn)代企業(yè)運(yùn)營(yíng)虛擬仿真綜合實(shí)訓(xùn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 招投標(biāo)及合同管理辦法-模板
- 佳木斯職業(yè)學(xué)院《臨床生物化學(xué)檢驗(yàn)學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 寧夏職業(yè)技術(shù)學(xué)院《顆粒技術(shù)》2023-2024學(xué)年第二學(xué)期期末試卷
- 2021護(hù)理考研護(hù)導(dǎo)錯(cuò)題試題及答案
- 中考英語(yǔ)高頻單詞專項(xiàng)訓(xùn)練題配套答案
- 火龍罐療法經(jīng)典課件
- 應(yīng)用寫(xiě)作(第六版) 課件 第1-4章 應(yīng)用寫(xiě)作概述-行政事務(wù)應(yīng)用文
- 核島通風(fēng)系統(tǒng)介紹
- 我見(jiàn)證改革開(kāi)放三十年課件
- xxxx智能化工程施工進(jìn)度計(jì)劃表
- 供應(yīng)商來(lái)料包裝運(yùn)輸存儲(chǔ)規(guī)范
- 搭橋術(shù)后護(hù)理查房
- 人工智能概論P(yáng)PT全套完整教學(xué)課件
- 第一章-運(yùn)動(dòng)選材概述課件
- 藏式建筑簡(jiǎn)介優(yōu)質(zhì)課件
評(píng)論
0/150
提交評(píng)論