最近在搞在SQL 2005安裝數據庫鏡像,中間遇到很多的錯誤,在此概括總結,以方便有須要的朋友參考。數據庫
直接上腳本,主機部分:日誌
---修改數據庫爲完整恢復模式
USE master;
ALTER DATABASE CZTest
SET RECOVERY FULL;
--------建立證書
USE master;
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '23987hxJ#KL95234nl0zBe';--建立數據庫密鑰,並提供密鑰使用密碼
CREATE CERTIFICATE HOST_A_cert WITH SUBJECT = 'HOST_A certificate' ,
START_DATE = '07/08/2014';
--------建立鏈接端口
CREATE ENDPOINT Endpoint_Mirroring
STATE = STARTED
AS
TCP ( LISTENER_PORT=5022 , LISTENER_IP = ALL )
FOR
DATABASE_MIRRORING
( AUTHENTICATION = CERTIFICATE HOST_A_cert , ENCRYPTION = REQUIRED ALGORITHM AES , ROLE = ALL );
----------備份證書
BACKUP CERTIFICATE HOST_A_cert TO FILE = 'D:\SQLBackup\HOST_A_cert.cer';
----------互換證書
--操做完畢
----------添加登錄名和用戶
CREATE LOGIN Login_B WITH PASSWORD = '2014sa';
CREATE USER User_B FOR LOGIN Login_B;
CREATE CERTIFICATE HOST_B_cert AUTHORIZATION User_B FROM FILE = 'D:\SQLBackup\HOST_B_cert.cer';
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO Login_B;--准許HOST_B_login登錄名鏈接到端口
-----------手工同步登陸名和密碼
----login B的sid=0x5AA61C2F8FFA0B45AC27EEB148083CD9
select sid,name from syslogins;
----建立鏡像(未成功 緣由:1.數據庫完整備份,事務日誌也要完整備份
---- 2.建立鏡像的SQL要首先在備份庫中執行,而後在主庫執行。順序不可顛倒)
---- 3.在端點配置中禁用了數據庫鏡像傳輸功能:解決辦法:DBCC TRACEON(1400,-1)或者安裝SP1事務
---- 4.在安裝SP1時遇到了身份驗證不能經過,錯誤顯示兩個實例,其中還有一個是reporting services,打開reporting services配置,選中數據庫鏈接,配置一下本身的 帳戶,
ALTER DATABASE ceshi SET PARTNER = 'TCP://192.168.137.13:5022';
ALTER DATABASE HxCreditBuy SET PARTNER = 'TCP://192.168.137.13:5022';
-----下面這句執行成功
ALTER DATABASE CZTest SET PARTNER = 'TCP://192.168.137.13:5022';
-------------==========檢查腳本======================
DROP LOGIN HOST_B_login
DROP USER HOST_B_user
DBCC TRACEON(1400,-1)
DROP MASTER KEY
DROP CERTIFICATE HOST_A_cert
--檢查主機和備機的證書是否存在:
select name, start_date, expiry_date from sys.certificates where name not like '##%'
--刪除鏡像數據庫證書
--drop the old cert for the principal login
use master
DROP CERTIFICATE HOST_A_cert
GO
use master
DROP CERTIFICATE HOST_B_cert
GO
--檢查鏡像端口
SELECT * FROM sys.endpoints where type=4
--刪除端口
use master
DROP Endpoint Endpoint_Mirroring
GO
------------------------------------------------------------------備機腳本------------------------------------------
ip
--------------備機 登陸名 sa 密碼 sa
--------建立證書
USE master;
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '23987hxJ#KL95234nl0zBe';
CREATE CERTIFICATE HOST_B_cert WITH SUBJECT = 'HOST_B certificate' ,
START_DATE = '07/08/2014';
--------建立鏈接端口
CREATE ENDPOINT Endpoint_Mirroring
STATE = STARTED
AS
TCP ( LISTENER_PORT=5022 , LISTENER_IP = ALL )
FOR
DATABASE_MIRRORING
( AUTHENTICATION = CERTIFICATE HOST_B_cert , ENCRYPTION = REQUIRED ALGORITHM AES , ROLE = ALL );
---------備份證書
BACKUP CERTIFICATE HOST_B_cert TO FILE = 'C:\SQLBackup\HOST_B_cert.cer';
---------互換證書
------操做完畢
------添加登陸名和用戶
CREATE LOGIN Login_A WITH PASSWORD = '2014sa';
CREATE USER User_A FOR LOGIN Login_A;
CREATE CERTIFICATE HOST_A_cert AUTHORIZATION User_A FROM FILE = 'C:\SQLBackup\HOST_A_cert.cer';
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO Login_A;
-----手工同步登陸名
USE master;
exec sp_addlogin
@loginame = 'Login_B',
@passwd = '2014sa',
@sid = 0x5AA61C2F8FFA0B45AC27EEB148083CD9 ;
----建立鏡像(未成功 緣由:1.數據庫完整備份,事務日誌也要完整備份
---- 2.建立鏡像的SQL要首先在備份庫中執行,而後在主庫執行,順序不可顛倒)
ALTER DATABASE HxCreditBuy SET PARTNER = 'TCP://lidongsh-a2628e:5022';
ALTER DATABASE ceshi SET PARTNER = 'TCP://lidongsh-a2628e:5022';
-----下面這句執行成功
ALTER DATABASE CZTest SET PARTNER = 'TCP://lidongsh-a2628e:5022';
----------===================================================================
ci