数据库镜像可以使用两种类型的传输安全性:Windows 身份验证或基于证书的身份验证,就证书验证的镜像实现做个学习笔记。 配置环境: HOST_A : Windows Server 2003 Standard Edition(SP2) SQL Server 2005 Enterprise Edition(SP2 9.00.3042.00) HOST_B : Windows Server 2003 Standard Edition(SP2) SQL Server 2005 Enterprise Edition(SP2 9.00.3042.00) 主体 HOST_A 镜像 HOST_B 一. 在主体数据库HOST_A 上: USE master. --a.创建数据库主密钥 CREATE MASTER KEY ENCRYPTION BY PASSWORD = madefuckgan! . GO --可用以下语句查看生成的数据库主密钥 --SELECT * from sys.symmetric_keys . --b.创建一个证书 CREATE CERTIFICATE DB_HOST_A_cert WITH SUBJECT = DB_HOST_A certificate for database mirroring , START_DATE = 12/31/2007 , EXPIRY_DATE = 12/31/2010 GO --SELECT * FROM sys.certificates. --c.创建镜像端点 CREATE ENDPOINT DB_MIRR STATE = STARTED AS TCP ( LISTENER_PORT=5021 , LISTENER_IP = ALL ) FOR DATABASE_MIRRORING ( AUTHENTICATION = CERTIFICATE DB_HOST_A_cert , ENCRYPTION = REQUIRED ALGORITHM RC4 , ROLE = ALL ). GO --SELECT * FROM sys.tcp_endpoints --SELECT * FROM sys.database_mirroring_endpoints. --d.备份证书 BACKUP CERTIFICATE DB_HOST_A_cert TO FILE = D:\db_A_run.cer . GO --e.创建登入 CREATE LOGIN TO_HOST_A_login WITH PASSWORD = openthedoorHostA! . GO CREATE USER TO_HOST_A_user FOR LOGIN TO_HOST_A_login. GO 二. 在镜像数据库HOST_B 上: USE master. --1.创建数据库主密钥 CREATE MASTER KEY ENCRYPTION BY PASSWORD = madefuckgan#2! . GO --可用以下语句查看生成的数据库主密钥 --SELECT * from sys.symmetric_keys . --2.创建一个证书 CREATE CERTIFICATE DB_HOST_B_cert WITH SUBJECT = DB_HOST_B certificate for database mirroring , START_DATE = 12/31/2007 , EXPIRY_DATE = 12/31/2010 GO --SELECT * FROM sys.certificates. --3.创建镜像端点 CREATE ENDPOINT DB_MIRR STATE = STARTED AS TCP ( LISTENER_PORT=5022 , LISTENER_IP = ALL ) FOR DATABASE_MIRRORING ( AUTHENTICATION = CERTIFICATE DB_HOST_B_cert , ENCRYPTION = REQUIRED ALGORITHM RC4 , ROLE = ALL ). GO --SELECT * FROM sys.tcp_endpoints --SELECT * FROM sys.database_mirroring_endpoints. --4.备份证书 BACKUP CERTIFICATE DB_HOST_B_cert TO FILE = D:\db_B_run.cer . GO --5.创建登入 CREATE LOGIN TO_HOST_B_login WITH PASSWORD = openthedoorHostB! . GO CREATE USER TO_HOST_B_user FOR LOGIN TO_HOST_B_login. GO