首页 > 数据库 > mysql教程 > 数据库备份和还原

数据库备份和还原

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-07 15:42:01
原创
1243 人浏览过

1.备份 if (DirectoryExists(EdtLJ.Text))=false then // EdtLJ.Text备份绝对路径 begin ForceDirectories(EdtLJ.Text); end; strsql:=' backup database Demo to disk=' ; strsql:=strsql+#39+EdtLJ.Text+'/'+EdtMC.text+#39; //EdtMC.text备份文件名称 Dia

 1.备份

if (DirectoryExists(EdtLJ.Text))=false then  //  EdtLJ.Text备份绝对路径
 begin
 ForceDirectories(EdtLJ.Text);
 end;
 strsql:=' backup database Demo to disk=' ;
 strsql:=strsql+#39+EdtLJ.Text+'/'+EdtMC.text+#39;  //EdtMC.text备份文件名称
 Dialogs.ShowMessage(strsql);
 with adoquery2 do
  begin
    close;
    sql.Text:=strsql;
    execSql;
    showmessage('备份成功!');
  end;

或者

//开始备份

      with adoquery1 do
       begin
             close;
             sql.Clear;
             sql.Add('Backup database library to disk=:p1 with init');
             parameters.ParamByName('p1').Value:=self.SaveDialog1.FileName;
            try
                Execsql;
               ShowMessage('备份成功!!');
            except
                ShowMessage('备份失败!!');
                exit;
            end;
       end; //End of 备份

2.还原

方法1

use master  --这样避免正在使用要还原的库
go

declare cur cursor for
  select spid from sysprocesses where dbid=db_id('Demo')
open cur
declare @spid int

declare @str varchar(100)

fetch next from cur into @spid
while @@fetch_status=0
begin
   set @str=ltrim(@spid)
   exec ('kill '+@str)
   fetch next from cur into @spid
end
close cur
deallocate cur

go

restore database Demo from  disk='d:/111.bak' with replace

方法2 
alter database Demo set offline with rollback immediate
restore database Demo from disk='E:/1.bak'  //还原语句
alter database Demo set online with rollback immediate

 

以上程序仅供参考,有什么不对的地方还请多多指教!

相关标签:
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
数据库数据
来自于 1970-01-01 08:00:00
0
0
0
数据库
来自于 1970-01-01 08:00:00
0
0
0
数据库文件导入
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板