ificate'' ,
4START_DATE = ''01/01/2008'';
5
--备机执行:
1USE master;
2CREATE MASTER KEY ENCRYPTION BY PASSWORD = ''killkill'';
3CREATE CERTIFICATE HOST_B_cert WITH SUBJECT = ''HOST_B certificate'',
4START_DATE = ''01/01/2008'';
5
2、创建连接的端点(主备可并行执行)
--主机执行:
1CREATE ENDPOINT Endpoint_Mirroring
2STATE = STARTED
3AS
4TCP ( LISTENER_PORT=5022 , LISTENER_IP = ALL )
5FOR
6DATABASE_MIRRORING
7( AUTHENTICATION = CERTIFICATE HOST_A_cert , ENCRYPTION = REQUIRED ALGORITHM AES , ROLE = ALL );
8
--备机执行:
1CREATE ENDPOINT Endpoint_Mirroring
2STATE = STARTED
3AS
4TCP ( LISTENER_PORT=5022 , LISTENER_IP = ALL )
5FOR
6DATABASE_MIRRORING
7( AUTHENTICATION = CERTIFICATE HOST_B_cert , ENCRYPTION = REQUIRED ALGORITHM AES , ROLE = ALL );
8
3、备份证书以备建立互联(主备可并行执行)
--主机执行:
1BACKUP CERTIFICATE HOST_A_cert TO FILE = ''D:\SQLBackup\HOST_A_cert.cer'';
--备机执行:
1BACKUP CERTIFICATE HOST_B_cert TO FILE = ''D:\SQLBackup\HOST_B_cert.cer'';
4、互换证书
将备份到D:\SQLBackup\的证书进行互换,即HOST_A_cert.cer复制到备机的D:\SQLBackup\。HOST_B_cert.cer复制到主机的D:\SQLBackup\
5、添加登陆名、用户(主备可并行执行)
以下操作只能通过命令行运行,通过图形界面无法完成。(截至文档编写结束,SQL Server2005的不定号为SP2)
--主机执行:
1CREATE LOGIN HOST_B_login WITH PASSWORD = ''killkill'';
2CREATE USER HOST_B_user FOR LOGIN HOST_B_login;
3CREATE CERTIFICATE HOST_B_cert AUTHORIZATION HOST_B_user FROM FILE = ''D:\SQLBackup\HOST_B_cert.cer'';
4GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [HOST_B_login];
5
--备机执行:
1CREATE LOGIN HOST_A_login WITH PASSWORD = ''killkill'';
2CREATE USER HOST_A_user FOR LOGIN HOST_A_login;
3CREATE CERTIFICATE HOST_A_cert AUTHORIZATION HOST_A_user FROM FILE = ''D:\SQLBackup\HOST_A_cert.cer'';
4GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [HOST_A_login];
5
三、建立镜像关系
以下步骤是针对每个数据库进行的,例如:现有主机中有5个数据库以下过程就要执行5次。
1、 手工同步登录名和密码
在第一章中提到数据库镜像的缺点之一是无法维护登录名,所以需要我们手工维护登录。
通常来说数据库都将会有若干个用户作为访问数据库的用户,并且数据库会有相应的登录名,但是在备机中缺少与之相对应的登录名,例如某业务系统使用’myuser’作为登录名访问数据库,但是在备机中没有’myuser’这个登录名,因此一旦主备切换,业务系