數(shù)據(jù)備份yu還原

數(shù)據(jù)備份yu還原

方式:

數(shù)據(jù)表備份

單表數(shù)據(jù)備份

SQL備份

增量備份

數(shù)據(jù)表備份

存儲引擎:innodb、myisam

innodb:只有表結(jié)構(gòu),數(shù)據(jù)全部存儲到 ibdata1 文件中(可以復(fù)制不能使用)

myisam:表、數(shù)據(jù)和索引全部單獨分開存儲(換任何地方都可以用)

-- 查看當(dāng)前MYSQL版本

select @@version;

-- 創(chuàng)建myisam表

create table my_myisam(

id int

)charset utf8 engine=myisam;

在下面的路徑查看創(chuàng)建的myisam表:

C:\ProgramData\MySQL\MySQL Server 5.7\Data\mydb

-- 向my_myisam表插入幾條記錄

insert into my_myisam values(1),(2),(3);

create database test charset utf8;

把在mydb數(shù)據(jù)庫創(chuàng)建好的my_myisam3個復(fù)制到新創(chuàng)建的test數(shù)據(jù)庫

單表數(shù)據(jù)備份

備份:

select */字段列表 into outfile 文件所在路徑 from 數(shù)據(jù)源;

-- 單表數(shù)據(jù)備份

select * into outfile 'E:/Sublime Text 3/1910/web/student.txt' from my_student;

select * into outfile 'E:/Sublime Text 3/1910/web/class.txt' from my_class;

藍色部分默認(rèn)是tab鍵

高級備份:

select */字段列表 into outfile 文件所在路徑 fields 字段處理 lines 行處理 from 數(shù)據(jù)源;

fields:字段處理,enclosed by(默認(rèn)'')、terminated by(默認(rèn)'\t')、escaped by(默認(rèn)'\\')

lines:行處理,starting by(默認(rèn)'')、terminated by(默認(rèn)'\r\n')

-- 指定備份處理方式

select * into outfile

'E:/Sublime Text 3/1910/web/class1.txt'

-- 字段處理

fields

enclosed by '"' -- 數(shù)據(jù)使用雙引號包裹

terminated by '|' -- 使用豎線分割字段數(shù)據(jù)

-- 行處理

lines

starting by 'START:'

from my_class;

數(shù)據(jù)還原:

load data infile 文件所在路徑

into table 表名[(字段列表)]

fields 字段處理

lines 行處理;

-- 刪除班級表數(shù)據(jù)

delete from my_class;

-- 還原數(shù)據(jù)

load data infile 'E:/Sublime Text 3/1910/web/class1.txt'

into table my_class

-- 字段處理

fields

enclosed by '"' -- 數(shù)據(jù)使用雙引號包裹

terminated by '|' -- 使用豎線分割字段數(shù)據(jù)

-- 行處理

lines

starting by 'START:';

SQL備份

備份:mysqldump.exe

適用于中小項目

mysqldump/mysqldump.exe -hPup 數(shù)據(jù)庫名字 [數(shù)據(jù)表名字1 [數(shù)據(jù)表名字2...]] > 外部文件路徑

整庫備份:

mysqldump/mysqldump.exe -hPup 數(shù)據(jù)庫名字 > 外部文件路徑

SQL還原數(shù)據(jù)(只管最后結(jié)果)

方案一:使用mysql.exe客戶端還原

不帶分號;的要\q退出在執(zhí)行

mysql.exe/mysql -hPup 數(shù)據(jù)庫名字 < 備份文件目錄

方案二:使用SQL指令還原

source 備份文件所在路徑

增量備份

備份的是系統(tǒng)日志(所有操作記錄)文件(指定時間段備份)

不會重復(fù),節(jié)省時間,不浪費磁盤空間

周期長,(適用于大項目),數(shù)據(jù)精確度高

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容