本文共 3230 字,大约阅读时间需要 10 分钟。
1. 环境配置
服务器1:sqlmirror01 IP:192.168.10.176服务器2:sqlmirror02IP:192.168.10.177操作系统:Windows 2012 R2安装 .Net Framework 3.5/4.0关闭服务器防火墙或设置白名单数据库版本:SQL Server 20142. 创建主密钥(非必需)use mastergocreate master key encryption by password='zaq12WSX'go3. 创建证书sqlmirror01执行use mastergocreate certificate sqlmirror01_cert with subject='sqlmirror01 certificate',expiry_date='2099-1-1'gosqlmirror02执行use mastergocreate certificate sqlmirror02_cert with subject='sqlmirror02 certificate',expiry_date='2099-1-1'go4. 创建镜像端点sqlmirror01执行use mastergocreate endpoint Endpoint_Mirroringstate=startedas tcp ( listener_port = 5022,listener_ip = all )for database_mirroring ( authentication = certificate sqlmirror01_cert, encryption = required algorithm aes, role = all )gosqlmirror02执行use mastergocreate endpoint Endpoint_Mirroringstate=startedas tcp ( listener_port = 5022,listener_ip = all )for database_mirroring ( authentication = certificate sqlmirror02_cert, encryption = required algorithm aes, role = all )go5. 备份证书sqlmirror01执行use mastergobackup certificate sqlmirror01_cert to file = 'C:\Certificate_files\sqlmirror01_cert.cer'gosqlmirror02执行use mastergobackup certificate sqlmirror02_cert to file = 'C:\Certificate_files\sqlmirror02_cert.cer'go6. 拷贝证书将sqlmirror01_cert.cer拷贝至sqlmirror02的C:\Certificate_files\将sqlmirror02_cert.cer拷贝至sqlmirror01的C:\Certificate_files\7. 创建登录名sqlmirror01执行use mastergocreate login sqlmirror02_login with password='abc@123456'gosqlmirror02执行use mastergocreate login sqlmirror01_login with password='abc@123456'go8. 创建使用该登录名的用户sqlmirror01执行use mastergocreate user sqlmirror02_user for login sqlmirror02_logingosqlmirror02执行use mastergocreate user sqlmirror01_user for login sqlmirror01_logingo9. 证书与用户关联sqlmirror01执行use mastergocreate certificate sqlmirror02_certauthorization sqlmirror02_userfrom file='c:\Certificate_files\sqlmirror02_cert.cer'gosqlmirror02执行use mastergocreate certificate sqlmirror01_certauthorization sqlmirror01_userfrom file='c:\Certificate_files\sqlmirror01_cert.cer'go10. 授予对远程镜像端点的登录名的 CONNECT 权限sqlmirror01执行use mastergoGRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [sqlmirror02_login]; go sqlmirror02执行use mastergoGRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [sqlmirror01_login]; go 11. 配置镜像伙伴sqlmirror01执行创建数据库CREATE DATABASE [Mirror_test_1]ON PRIMARY ( NAME = N'Mirror_test_1', FILENAME = N'C:\dbdata\Mirror_test_1.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )LOG ON ( NAME = N'Mirror_test_1_log', FILENAME = N'C:\dbdata\Mirror_test_1_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)GO备份数据库backup database Mirror_test_1 to disk='C:\backup\Mirror_test_1.bak' with compression,checksum将备份拷贝至sqlmirror02sqlmirror02执行restore database Mirror_test_1 from disk='C:\backup\Mirror_test_1.bak' with norecovery连接镜像sqlmirror02执行use mastergoALTER DATABASE Mirror_test_1 SET PARTNER = 'TCP://sqlmirror01:5022'; gosqlmirror01执行use mastergoALTER DATABASE Mirror_test_1 SET PARTNER = 'TCP://sqlmirror02:5022'; go更改为高性能模式镜像主体sqlmirror01执行use mastergoALTER DATABASE Mirror_test_1 SET PARTNER SAFETY OFF go转载于:https://blog.51cto.com/aimax/2122535