SQL2008鏡像
/*************************************************
*sql鏡像的具體配置步驟說明
*Crate DataTime:
*2016-0205-2016-02-06研究成功
*Expian:
*本實例沒有配置見證伺服器,非域環境,資料庫版本為SQL2008數據中心版
*兩臺機,系統版本為SERVER 2012,IP分別為:192.168.1.25(A)、192.168.1.26(B)
*其中A為主資料庫,B為鏡像庫;
*遇到的問題記錄如下:
*1)兩臺機都要放1433、5022--5022TCP,UDP都要開
*2)主資料庫備份時要用語句備份
*3)鏡像伺服器在恢復資料庫時選擇NORECOVERY(不回滾),默認為RECOVERY(回滾);
*恢復後會發現B數據中一直處於還原狀態,屬於正常現象。
*如果用的是RECOVERY,在雙方鏡像時會出現1416,沒有為鏡像配置XX資料庫。
*後在國外一網站上查到原因了,順利解決!
*證書登陸的帳號要在雙方mast庫中添加一下,否會出錯
*鏡像暫停後,再進行連接會提示無法驗證用記有,在配置安全-->驗證-->添加副鏡像庫的SQL登陸名即可
*---在網上找了很多,都沒有解決這個問題,下面記錄一下外國友人說的方法------
*I hope now it will be easy. First, backup the database on primary server,
*thern copy the backup to the mirror server and then restore the database with NORECOVERY option.
*Then backup the LOG (I hope your database is in FULL recovery mode) on the primary database,
*copy to mirror and restore this log with NORECOVERY option. And then try to start mirroring as soon as you can.
* – Alex_L Mar 28 '12 at 7:43
*-----------------------------------------------------------------------------------------
*資料庫鏡像尚未完全啟動解決方法,在兩臺機上用SA也就是相同的帳號和密碼來啟動資料庫,問題解決
***************************************************/
use master;--創建主密鑰
create master key encryption by password='xingxun66**';
go--的25上創建證書
create certificate as_a_cert--證書名
with subject='as_a_cert',
expiry_date='01/01/2099';--終止時間
go
--的25上用上面的證書創建資料庫的鏡像端點
if not exists(select 1 from
sys.database_mirroring_endpoints)
begin
create endpoint [databasemirroring] state=started as tcp(
listener_port=5022 ,listener_ip=all
)for database_mirroring(
authentication=certificate as_a_cert,encryption=required algorithm aes,role=all
);
end
---備份證書
backup certificate as_a_cert
to file='c:\as_a_cert.cer';
go
--將證書對拷
--創建帳號
--同步證書
--映射帳號sql
--注下面語句要一起運行
create login b_login2 with password='xingxun66**';
create user b_user2 for login b_login2;
create certificate as_b_cert authorization b_user2 from file='C:\zhengshu\as_b_cert.cer';
grant connect on endpoint::databasemirroring to[b_login2];
go
*兩臺伺服器都要依次執行,例A中要註冊B證書,B中要註冊A證書,登陸名可以相同,映射證書名也可以相同
---備份主體資料庫--依次執行
alter database news set recovery full;
--2--
backup database news
to disk='c:\news.bak' with format;
---3--
backup log news to disk='c:\news.bak';
------
/*備份完後將備份拷貝到鏡像機--
恢復該備份:還原時選擇不操作的回滾+覆蓋資料庫,默認就操作回滾--
*/
----在鏡像伺服器上執行--
alter database news set partner='tcp://192.168.1.25:5022';--連接主伺服器
---2--
/*在主伺服器上運行*/
alter database news set partner='tcp://192.168.1.26:5022';--連接鏡像伺服器
/*delete ZhengShu
use master;
drop certificate as_b_cert
*/
--上面的方面在B伺服器上也執行只是要把證書名和登陸名改一下;
--成功後會看到主伺服器上顯示"主體已同步",B鏡像伺服器上顯示「正在還原」
--到這一步就大功告成了,可以來測試了,通過故障轉移來測試數據是否同步!
--2016/02/06/14:53/福田國際電商務產業園/
--重新配置
ALTER DATABASE hyinfoa SET PARTNER = 'TCP://210.83.225.50:5022'
GO