關係型資料庫(22)
作者同類文章
x備份
與恢復1. 備份策略
2. 作業系統級備份:
讓資料庫
離線use master
goalter database [mysqlserver]
set offline
go讓資料庫聯機
use master
goalter database [mysqlserver]
set online
go3. 資料庫全備份
backup database [mysqlserver]
to disk = n'c:program filesmicrosoftsql
servermssql.1mssqlbackupmysqlserver.bak'
with description = n'2008-03-11',
noformat, init,
name = n'mysqlserver-full database backup',
skip, norewind, nounload, stats = 10
godeclare @backupsetid as int
select @backupsetid = position
from msdb..backupset
where database_name=n'mysqlserver'
and backup_set_id=
(select max(backup_set_id) from msdb..backupset where database_name=n'mysqlserver' )
if @backupsetid is null
begin
raiserror(n'verify failed. backup information for database ''mysqlserver'' not found.', 16, 1)
endrestore verifyonly
from disk = n'c:program filesmicrosoft sql servermssql.1mssqlbackupmysqlserver.bak'
with file = @backupsetid, nounload, norewind
go4. 資料庫增量備份
backup database [mysqlserver]
to disk = n'c:program filesmicrosoft sql servermssql.1mssqlbackupmysqlserver.bak'
with differential , noformat, noinit,
name = n'mysqlserver-differential database backup',
skip, norewind, nounload, stats = 10
godeclare @backupsetid as int
select @backupsetid = position from msdb..backupset where database_name=n'mysqlserver' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=n'mysqlserver' )
if @backupsetid is null begin raiserror(n'verify failed. backup information for database ''mysqlserver'' not found.', 16, 1) end
restore verifyonly from disk = n'c:program filesmicrosoft sql servermssql.1mssqlbackupmysqlserver.bak' with file = @backupsetid, nounload, norewind
go5. 事務日誌備份
backup log [mysqlserver]
to disk = n'c:program filesmicrosoft sql servermssql.1mssqlbackupmysqlserver.bak'
with noformat, noinit, name = n'mysqlserver-transaction log backup',
skip, norewind, nounload, stats = 10
go6. 資料庫恢復:
restore database [mysqlserver]
from disk = n'c:program filesmicrosoft sql servermssql.1mssqlbackupmysqlserver.bak'
with file = 6, nounload, stats = 10
gorestore database [mysqlserver]
from disk = n'c:program filesmicrosoft sql servermssql.1mssqlbackupmysqlserver.bak'
with restricted_user, file = 6,
move n'mysqlserver_pri01' to n'e:mysql_pri01.mdf',
move n'mysqlserver_log' to n'e:mysql2_log.ldf',
move n'mysqlserver_sec01' to n'e:mysql2_sec01.ndf',
move n'mysqlserver_sec02' to n'e:mysql2_sec02.ndf',
keep_replication, nounload, replace, stats = 10
go7. 分離與附加
例:資料庫分離:
use [master]
goexec master.dbo.sp_detach_db @dbname = n'mysqlserver', @keepfulltextindexfile=n'true'
go例:資料庫附加:
create database mysqlserver2
on ( filename = 'c:program filesmicrosoft sql servermssqldatamysqlserver2.mdf' )
for attach
go
資料庫備份和恢復
這裡介紹兩種方法 1.mysqldump mysqldump不需要登入到資料庫中就可以備份和恢復庫和表 1 備份 mysqldump uroot p 123123 mytest mnt mytest bak date f sql 注意這裡是在命令列操作的,不是在mysql資料中,所以也不會有冒號 2...
資料庫的備份和恢復
1.資料庫的備份mysqldump命令 將create和insert into語句儲存到文字檔案 屬於dos命令 mysqldump 選項引數 u p h 需備份資料名 需備份表名 備份的檔名 mysqldump是dos系統下的命令 在使用時無須進入mysql命令列,否則將無法執行。2.使用mysq...
資料庫的備份和恢復
一 建立資料庫 1 資料庫的建立 語法 create database if notexists 資料庫名 create database if notexists 資料庫名 create speci cation create speci cation 示例 建立乙個名為mysweet的資料庫 資...