1- Introduction about Database Mirroring Concept
2- Reference (8 Blogs )
3- Note
4- Database mirroring operation mode
5- Database Mirroring Requirement
6- Advantage of Database Mirroring
7- Disadvantage of Database Mirroring
8- Database Mirroring Enhancement in SQL Server 2008
9- Database Mirroring Installation Step by Step
10- High Availability Mode [Automatic Failover]
11- High Availability Mode [Manual Failover]
12- High Safety Mode Without witness server [Manual Failover]
13- Stander listener port in database mirroring
14- Check SQL server mirroring availability
15- Add or replace witness server to an existing mirroring database
16- How to monitor Database Mirroring
17- Mirroring in workshop not in DC (Domain Controller)
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
High availability solution database mirroring
1. Database Administration Community (https://mostafaelmasry.wordpress.com)
SQL Server Technical Article
High Availability Solution Database Mirroring in SQL Server 2008 R2
Writer: Mustafa EL-Masry
Technical Reviewer: SQLSERVER Performance tuning (http://sqlserver-performance-tuning.net/)
Published: Jan 2015
Applies to: SQL Server 2008 R2, 2012
Slide Share: http://www.slideshare.net/MostafaElmasry3
About The Writer
I am Mustafa El-MasrySeniorDatabase administratorandDB Analyst I
am ExpertDatabase performance tuning, Ihave deeppractical
knowledge aboutT-SQLperformance,HW Performance issues,Data
Warehousinganddatamart solutions,SQLServerReplication,Clustering
solutions(Active Activeandactive passive)andDatabase Designsfor
differentkindsof systems,HAG,divingdeeplymore :
I am Founderof Community:SQL
DATABASEADMINISTRATION:http://mostafaelmasry.wordpress.com/
Linkedin: https://www.linkedin.com/in/mostafaelmasry
My CommunityAnnual report
: https://mostafaelmasry.wordpress.com/2014/annual-report/
I am Technical Writerand Reviewer:http://www.slideshare.net/MostafaElmasry3/
I am Audience MarketingManager and Executive Board member:SQLSERVER PERFORMANCE
TUNING http://sqlserver-performance-tuning.net/
One HundredPOST :http://sqlserver-performance-tuning.net/?p=5244
FluentParticipator at MicrosoftForums of SQL Serverat http://Social.technet.microsoft.com
More than +175 Post in SQL Server Technology: http://sqlserver-performance-tuning.net/?p=4526
MicrosoftProfile:https://www.mcpvirtualbusinesscard.com/VBCServer/EngMostafaElamsry/profile
3. Database Administration Community (https://mostafaelmasry.wordpress.com)
Introduction and overview
Database mirroringisa primarilysoftware solution forincreasingdatabase availability.Mirroringis
implementedona per-database basisandworksonlywithdatabasesthatuse the full recoverymodel.
The simple andbulk-loggedrecoverymodelsdonotsupportdatabase mirroring.Therefore,all bulk
operationsare alwaysfullylogged.Database mirroringworkswithanysupporteddatabase compatibility
level. Database mirroringisusedbyMicrosoft SQL Server,arelational database managementsystem
(RDBMS) designedforthe enterpriseenvironment.Twocopiesof asingle database reside ondifferent
computerscalled serverinstances,usuallyinphysical locationsseparatedbysome distance.The
principal (orprimary) serverinstance providesthe database toclients.The mirror(orsecondary) server
instance actsas a standbythat can take overin case of a problemwiththe principal serverinstance.
4. Database Administration Community (https://mostafaelmasry.wordpress.com)
Reference
Note
In database mirroring section you have 3 servers (principle, mirroring, and witness)
The database will be in the principle server and the application will be connect to the
principle server then you will take backup (Full + log) from the database in the principle
server the make restore to this backup with no recovery option in the mirroring server so
the record will copy from the principle server to the mirror server.
Witness server will be monitoring to the principle and the mirroring server.
You can setupthe principle serverindomainandthe mirroringserverinanotherdomain
What happensif the principle serverdown in highavailabilitymode?
If the principle serverdownthe mirroringserverwill be the new principle serverandthe applicationwill
be connectautomaticallytothe newprinciple server(mirroringserver)
What happenedwhenthe applicationconnect to the database in the principle server?
Whenthe Applicationconnecttothe principle serverandusersmake anytransactiononthisdatabase
the record will write inlogpuffermemoryinprinciple serverthenwrite it inlogfile indatabase thenthe
logpuffersendthe recordto the log puffermemorytothe mirroringserverthenthe logpufferwrite this
record in log file in database. Then the mirror server send to the principle server massage to know the
principle the transaction is succeed then the principle tell the application the transaction is succeed.
Mirroring in SQL Server (8/8)
Mirroring in SQL Server (7/8)
Mirroring in SQL Server (6/8)
Mirroring in SQL Server (5/8)
Mirroring in SQL Server (4/8)
Mirroring in SQL Server (3/8)
Mirroring in SQL Server (2/8)
Mirroring in SQL Server (1/8)
5. Database Administration Community (https://mostafaelmasry.wordpress.com)
Database mirroring operation mode
You can setupthe mirroringserverin3 modes
1. High availability.
In highavailabilityyouneed3servers
(principle server,mirroringserver,witness
server) sointhisoperationmode the
applicationconnectonthe principle server
thenthe transactionwrite inlogfile then
the principle serversendthe recordtothe
mirrorserverinlog file the mirrorsendto
the principle (the recordiscommit) then
the principle sendtothe applicationthe transactioniscommitted
2. High safety.
In highsafetymode we don'tneedtothe witnessserverwe willneedinthissectiontothe
principle serverandthe mirrorserveronlysothere'sno automaticfailoverinhighsafetymode.
Andthe operationwill be same inthe highavailabilitymode[applicationconnectonthe
principle serverthenthe transactionwrite inlogfile thenthe principle serversendthe recordto
the mirror serverinlog file the mirrorsendtothe principle (therecordiscommit) thenthe
principle sendtothe applicationthe transactioniscommitted]
Remarks: the difference betweenhighavailabilitymode andhighsafetymode isAutomatic
failoverinhighavailability will foundAutomaticfailoverbutinhighsafetywill notfound
Automaticfailover.Soif the principle serverdownyouhave problembecause youwillmake
manuallystart
The mirroringservertobe principle server.Notlike inhighavailabilitymode thisoperation
make automaticallybecause thisoperationmodehave automaticfailover.
3. High performance.
In highperformance mode youneed2server(principle server,mirrorserver) like highsafety
mode . So the differencebetweenthe highperformancemode andhighsafetymode isinhigh
performance the applicationsendthe transactiontothe principle serverinlogfile thenthe
principle sendthe recordtothe mirrorserverand sendtothe applicationthe transactionis
committedsothe principle server don'twaitthe mirrorserverlike (highsafetymodeandhigh
availabilitymode)
6. Database Administration Community (https://mostafaelmasry.wordpress.com)
Operation mode servers Automatic failover Principle wait the
mirror
High availability 3 servers Yes Yes
High safety 2 servers No Yes
High performance 2 servers No No
In the finale Iexplainwhatismirroring?,whatisthe operationmode inmirroring?,whatisthe
difference betweenoperationmode inmirroring?,rememberItell youhighsafetyandhigh
performance notneedwitnessserverbutyoucan create witness serverinthisoperationmode butit
will make problemswhityousodon'tmake witnessserverinhighsafetymode andhighperformance
mode
Database MirroringRequirement
The database and file locationshouldbe same.
Collectionandmastercode page shouldbe same inthe principle andmirrorserver.
Database name shouldbe same inthe principle andmirrorserver.
You cannot mirrormore the 10 databasesin32 bitserversyoucan in64 bitserverbutnot
recommended.
You cannot use attach/de attach you can use backup andrestore.
Portsin mirroringshouldbe openinginfirewall orclose the firewall.
ServicesaccountInSQL and SQL agentshouldbe same in all servers.
The mirroringnot supportthe cross database transaction& distributedtransactionlog
SQL servernumbershouldbe same butyoucan setupprinciple serveronSQLServer2008
service pack1 andthe mirroron SQL Serverservice pack2.
7. Database Administration Community (https://mostafaelmasry.wordpress.com)
Advantage of Database Mirroring
1- Doesnot require special hardware (suchassharedstorage,heart-beatconnection) andcluster
ware,thuspotentiallyhaslowerinfrastructure cost
2- Database mirroringsupportsfull-textcatalogs
3- Hardware and software upgrade that'sveryeasy.
Remark: If youwant upgrade the mirrorserverfromSQL server2008 R2 todenial youmust
pass the mirroringinthissectionthenafterupgrade startthe mirroringagain
4- Increasesthe dataprotection(disasterrecovery).
5- Increasesthe database availabilityif youuse the Syncmode.
6- Cost of database mirroringislessthanclustering.
7- It's robustand efficientthanlogshippingandreplication.
8- Failoverisfastcompare to cluster
9- Mirror servercan be usedto host databasesforotherapplicationsnotlike clustering.
Disadvantage of Database Mirroring
1- Mirroringdoesn'tsupportfile stream.
2- Mirror serverisnot available fordatabase readonly.
3- Mirror serverworkingindatabase level notinserverlevelnotlike clustering(inclustering
failover youmake thisinserverlevelonall database inthisserverinloginsinjobslike this)
Database Mirroring Enhancement in SQL Server 2008
1) Database mirroringautomatic page repair.
If a page on the principle ormirrorserveriscorrupt,it isautomaticallyreplacedwith
the correspondingcopyonitspartner
Some page typescannotbe automaticallyrepaired:
File headerpages
Database boot page
Allocationpages
2) CompressedData flow
Data Flowbetweenthe principle andmirrorserverisnow compressedtoimprove
performance.
3) Manual Failover
Manual failovernolongerrequire adatabase restart
4) Log performance
log-sendbuffers
Page read-ahead
Write-aheadonthe incominglogstreamonthe mirrorserver
Reference:http://www.sqlserver-training.com/database-mirroring-enhancements-in-sql-server-2008-
from-2005/-
8. Database Administration Community (https://mostafaelmasry.wordpress.com)
Database Mirroring Installation Step by Step
Let's start to setupmirroringserverinSQLserver2008 R2 in the firstI will setupSQLServer2008R2 with
three instance
1. Principle instance(SQLSERVER2008R2A)
2. Mirroringinstance (SQLSERVER2008R2B)
3. WitnessInstance (SQLSERVER2008R2C)
In myexample I will make mirroringtype highavailability(Synchronize mode)
In principle serverIwill create database Mirroring_DB
Take full backupMirroring_DB.bak
thentake log TransactionbackupMirroring_DB.trn
Make restore tothisbackup full mirroringserver withNorecoveryoption
Thenright clickonMirroring_DB >>Tasks>>Restore>>TransactionLog
ThenSelectyourtransactionlogbackup(Mirroring_DB.trn)
Don’tforgetrestore withnorecoveryoption
9. Database Administration Community (https://mostafaelmasry.wordpress.com)
High Availability Mode [Automatic Failover]
Principle Server
Rightclick on database Mirroring_Db >> tasks >> Mirror >> Configure Security
You will ask if you wantto setup witness server or not? selectyes.
Then you will ask to selectyour principle server [connect to Elmasry-PCPrinciple]and make the port is 5021 and
the endpointname is Principle then Click next
You will ask again to selectyour Mirroring server [connectto Elmasry-PCMirroring]and make the port is 5022
and the endpointname is mirroring then click next.
You will ask again to selectyour witness server [connectto Elmasry-PC]and make the port is 5023 and the
endpointname is Witness then click next .
In this step he will ask you to put your user name in your windows and this user mustbe add in the SQL Server
so I write my username is [mypc namewindows username][Elmasry-PCElmasry].then click finish
SQL server after you click finish itwill make configuration to the Principle Server , Mirroring Server , Witness
Server
After this configuration is finish SQL server will give you massage if you want to Start mirroring or not selectstart
and Waite few mints then mirroring will startand you see the status is [Synchronized: the databases are fully
synchronized]
Nowgo to make refreshtothe servers[principle - mirroring]
10. Database Administration Community (https://mostafaelmasry.wordpress.com)
Principle Server[Elmasry-PCPrinciple]
1- Create Table Name Employee
CREATE TABLE Employee
(Emp_Id INT NOT NULL PRIMARY KEY IDENTITY,
Emp_Name NVARCHAR(50) NOT NULL,
Tel NVARCHAR(12) NULL)
2- Insert data in this table
INSERT INTO dbo.Employee
( Emp_Name, Tel )
VALUES ( N'Mostafa', -- Emp_Name - nvarchar(50)
N'0172788327' -- Tel - nvarchar(12)
) , ('Mohamed' , '015876565645')
3- Nowif you selectdatafromEmployee Table youwill see2rows
4- Rightclickon the principle serverandmake stoptothe server
Mirroring Server[Elmasry-PCMirroring]
1- Refreshthe server(youwillsee the database change frommirroringtoprincipledatabase andif
youopenthe database you will see the Employee table andthe 2 rows
2- Nowtry to insertinthistable another2 rows
11. Database Administration Community (https://mostafaelmasry.wordpress.com)
INSERT INTO dbo.Employee
( Emp_Name, Tel )
VALUES ( N'Omar', -- Emp_Name - nvarchar(50)
N'0172788327' -- Tel - nvarchar(12)
) , ('Kemo' , '015876565645')
3- Stopthe serverandstart the principle server[Elmasry-PCPrinciple] youwill seethe database is
mirroringmake stopto the Mirroringserver[Elmasry-PCMirroring] youwill see the difference
the mirroringdatabase inthe principle serverwill change toPrinciple severandif youopenthe
Employee table youwillsee 4rowsnot 2 because the 2 rowsyou insertintodatabase in
mirroringservertransferautomaticallytoanotherserver
Before Istart to explainMirroringHighSafetymode Iwill explainsomethingisverygoodthat’sis
manual FailoverYesyoucan make manual failoverinthe previousExampleImake Failover(meaning
change the serverprinciple will be the mirroringandthe mirroringwillbe the principle) Imake this
operationbutAutomaticallywhenImake stoptothe serverandthisoperationmake Automatically
because Imake mirroring[HighAvailability] butinthe manual failoveryoucanmake the same
operationbyyourhand :
1- Go to principle serverthenrightclickandselecttasks>>> Mirror
2- ThenClickon Failoveryouwill seethe massage Clickyes
3- Thenmake refreshtothe serveryouwill see the change
12. Database Administration Community (https://mostafaelmasry.wordpress.com)
High Availability Mode [Manual Failover]
Before Istart to explainMirroringHighSafetymode Iwill explainsomethingisvery goodthat’sis
manual FailoverYesyoucan make manual failoverinthe previousExampleImake Failover(meaning
change the serverprinciple will be the mirroringandthe mirroringwillbe the principle) Imake this
operationbutAutomaticallywhenImake stoptothe serverandthisoperationmake Automatically
because Imake mirroring[HighAvailability] butinthe manual failoveryoucanmake the same operation
by yourhand :
Go to principle serverthenrightclickandselecttasks>>>>> Mirror
ThenClickon Failoveryouwill seethe massage Clickyes
Thenmake refreshtothe serveryouwill see the change
High Safety Mode Without witness server [Manual Failover]
In Highsafetymode if the principle serverdownthe mirroringwill be disconnectbutif youwantto
make the mirroringDB is principle DBinhighAvailabilitySQLServermake thisoperationAutomatically
because inthismode youhave AutomaticFailoverbutdon’tworryyoucan make thisbycode [Ilisten
someone tell me Whywe can'tmake the mirroringisprinciple byManual failoverItell himbecause the
mirroringmode ishighsafetyandthe principle serverisdownsothe mirroringserverisdisconnectedso
if you make rightclickon the mirroringDB thenSelecttasksthenmirroryouwill see the buttonof
FailoverisDisable]sowe have one choice orone way to make the MirroringDB isprinciple DBto allow
the applicationtoconnectThisWay is ByCode let'sstart to explainthe Mirroring[HighSafetyMode]
13. Database Administration Community (https://mostafaelmasry.wordpress.com)
Principle Server[Elmasry-PCPrinciple]
1- Rightclickon mirroringdatabase >>>> tasks>>>> Mirror
2- Delete the servernetworkaddresstothe witnessserver.automaticyouwillsee the SQLserver
change your mode fromhighavailabilitymode tohighsafetymode >>>>> clickok .
3- Rightclickon the principle server>>>> thenselectstop.
4- The serverwill be down
Mirroring Server[Elmasry-PCMirroring]
1- Refreshthe MirroringServer
2- You will see the database [Mirroring_DB] isDisconnected/inrecovery.
3- NowI will Execute SQLStatementonmasterdatabase inmirroringseverthisstatementwill
change the mirroring_DBfrom mirrorto principle
USE master
GO
ALTER DATABASE Mirroring_DB SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS
4- If you make start to the Principle server[Elmasry-PCPrinciple] youmustgoto the Mirroring
Severandright clickonMirroring_Db >>>Tasks >>>>Mirror >>>> Make resume toreturn the
mirrorto work.
5- HighPerformance Mode like HighSafetymode butif youwantto know the difference between
highsafetymode andhighperformance mode see partno1
14. Database Administration Community (https://mostafaelmasry.wordpress.com)
Stander listener port in database mirroring
If we will buildthe entire instance (Principle,mirroring,Witness) inthe same serveratthistime you
shoulduse difference portsExample:
Principle Serveruse the Standerportnumber5021
MirroringServeruse the Standerport number5022
WitnessServeruse the Standerportnumber5023
But if youwill builditindifference serversyoucanuse one port like: 5021 butdon’tforgetto Disable
Firewall ormustbe openthese portsonthe Firewall.
Check SQL server mirroring availability
We can checkSQL Servermirroringisrunningor bydifference steps:
1- port number listener:openCMD andwrite thisCommand”netstat -an” youwill see the
3 port forthe 3 ServersPrinciple–mirroring– WitnessalsoI see the 3 port because I
setupthe 3 SQL ServerInstance inthe same WindowsServer
15. Database Administration Community (https://mostafaelmasry.wordpress.com)
2- EventViewerforWindowsServer
3- SQL ServerDatabase Log
4- CheckEndpoint Status
16. Database Administration Community (https://mostafaelmasry.wordpress.com)
Add or replace witness server to an existing mirroring database
AfterI finishmyworkinDatabase MirroringwithoperationMode (highSafety).i exploreritwill notbe
Automaticfailoverbecause thisoptionif youneedityoumustconfigure yourmirroringwithoperation
mode (HighAvailabilitySynchronous) andthisOperationMode need3Servers(Principle ,Mirroring,
Witness) Soi will Shownow howtoadd or Replace mirroringDatabase WitnessServer
1- Nowthismy mirroringoperationmode it’shighsafetywithoutautomaticandthe witness
Servernotconfigured.
2- Clickon Configure Securityafterthismirroringwill Askyouif youneedtoConfigure Witness
Serveror notSelectyes
18. Database Administration Community (https://mostafaelmasry.wordpress.com)
6- Configure WitnessServerandthe port listener
7- Put ServicesAccount inmyexperience if youworkinginWorkgroupandyourall instance inthe
same windowslike thisexample create new userAdministratoronyourpc and addhimin SQL
Serverloginthe use it else if youuse Workgroupbutthe SQL Serversnotall inthe Same pc you
will use 3 Windowsor2 create CertificationinyourSQLServerandI will show itinthe nextpost
whoto create Mirroring WithLoginCertification.
19. Database Administration Community (https://mostafaelmasry.wordpress.com)
8- AfterthisStepClickfinishNoyourdatabase witnessisConfigured
Nowyour ConfigurationisComplete andif youcompare betweenimagesno8 andimage no 1 you will
see the difference youwill seenowwe have MirroringwithoperationmodehighsafetyWithAutomatic
failover
NOTE:
In Stepno6 you will See Iwrite the port no is5023 but wheni finishmyStepsandarrive to stepno8
thenclickon ok I reactive thisError:
TITLE: MicrosoftSQL ServerManagementStudio ——————————
AlterfailedforDatabase ‘ACC2012′. (Microsoft.SqlServer.Smo)
For help,click:onthislink
20. Database Administration Community (https://mostafaelmasry.wordpress.com)
——————————ADDITIONALINFORMATION:
An exceptionoccurredwhileexecutingaTransact-SQLstatementorbatch.
(Microsoft.SqlServer.ConnectionInfo)
——————————
The ALTER DATABASEcommandcouldnotbe sentto the remote serverinstance ‘TCP://IT-PC:5023′.The
database mirroringconfigurationwasnotchanged.Verifythatthe serverisconnected,andtryagain.
(MicrosoftSQL Server,Error:1456)
For help,click:onthislink
——————————BUTTONS:
OK ——————————
I don’tknowwhatis error I searchmore and more on the internetbut Idon’t foundgoodSolutionbut
whenI checkedthe SQLServerlog I see somethingsay{ SQL Servercannotlistentothe port No5023 }
So I Reconfiguredthe mirroringagainandChange the portfor the WitnessServerform5023 to 5024 it’s
Workingnowverygood
21. Database Administration Community (https://mostafaelmasry.wordpress.com)
How to monitor Database Mirroring:
I will monitordatabase mirroringfromManagementStudioandbyT-SQL
1- I will StopmirroringServertoinputtransactionintoPrinciple ServerandSee the logwhat
happenedinItGo to your database MirroringinPrinciple Server>> Write Click>>> tasks
>>>Lunch Database mirroringmonitor
2- Create Table onPrinciple Server andinsert10000 RecordintoNew table
CREATE TABLE TEST( A INT, B INT)
DECLARE @I INT=0
WHILE @I < 100000
BEGIN
INSERT INTO TEST VALUES(@I,@I)
SET @I=@I+1
END
SELECT COUNT(*) FROM TEST
22. Database Administration Community (https://mostafaelmasry.wordpress.com)
3- Nowrun the Scriptand insertthe Data thenlet’sgoto Checkthe monitortoSee whathappened
24. Database Administration Community (https://mostafaelmasry.wordpress.com)
Check the database mirroring information:
SELECT M.database_id , D.Name , M.mirroring_state_desc ,
M.mirroring_role_desc,M.mirroring_partner_name , M.mirroring_partner_instance,
M.mirroring_witness_name , M.mirroring_witness_state_desc
FROM sys.database_mirroring as M inner join Sys.databases as D
on M.database_id = D.database_id
Where D.database_id > 4
25. Database Administration Community (https://mostafaelmasry.wordpress.com)
Mirroring in workshop not in DC (Domain Controller)
Nowif I have 3 Serverswith three SQLserverInstance butthisserversnottrusted= Notin domainthis
serversinworkgroupbut nowI won’tto create mirroringbut the laststepin MirroringConfiguration
needfromthe ServicesAccountWhatI will write andwithnotrusted.So what we can do to make these
serversistrusted.
Solution:
We will make linkbetweenthisSQLServerinstance thislinknotthe linkedserverfeature butthat’s
meaningwe will make masterkeyandCertificate onall ServersthenCreate usersinthe 3Serversthen
give grant ConnectiontothisUsersonthis MirroringEndpointExample
Servername Certification user
ServerA (Principle) CERT_A User_A
ServerB (Mirror) CERT_B User_B
ServerC (Witness) CERT_C User_C
Now I create differenceCertificate and useronthe serversthenIwill
Create Certificate ServerBand C onserverA
Create Certificate ServerA andC on ServerB
Create Certificate ServerA andB on ServerC
AlsoI make these Steps onuserthengive the 3 userin the ServerA and B and C grant Connectionon
MirroringEndpointbythisWay I make Bridge betweenthe 3Servers
1- Step 1 on Principle Server:
USE MASTER
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD ='Admin123'
GO
CREATE CERTIFICATE Principle_cert
WITH SUBJECT = 'Principle certificate'
GO
CREATE ENDPOINT End_Mirroring
STATE = STARTED
26. Database Administration Community (https://mostafaelmasry.wordpress.com)
AS TCP (LISTENER_PORT = 5025 , LISTENER_IP=ALL)
FOR DATABASE_MIRRORING
(AUTHENTICATION = CERTIFICATE Principle_cert , ENCRYPTION=REQUIREDALGORITHM RC4 ,
ROLE=ALL)
GO
BACKUP CERTIFICATE Principle_cert
TO FILE ='C:certificatePrinciple_cert.cer'
GO
2- Step no 2 On Mirror Server:
USE master
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Admin123'
GO
CREATE CERTIFICATE Mirror_cert WITH SUBJECT = 'Mirror certificate'
GO
CREATE ENDPOINT End_Mirroring
STATE=STARTED
AS TCP (LISTENER_PORT= 5026,LISTENER_IP=ALL)
FOR DATABASE_MIRRORING
(AUTHENTICATION=CERTIFICATE Mirror_cert , ENCRYPTION = REQUIREDALGORITHM RC4 , ROLE=ALL)
GO
BACKUP CERTIFICATE Mirror_cert
TO FILE='D:certificateMirror_cert.cer';
GO
3- Step No3 on Principle Server:
Copythe Certificate”Mirror_cert”FromMirror Servertothe Principle Serverbecause IwillCreate the
Certificate MirroringServeronPrinciple Serverwiththe Username Mirror_user
USE MASTER
GO
27. Database Administration Community (https://mostafaelmasry.wordpress.com)
CREATE LOGIN Mirror_login WITH PASSWORD='Admin123'
GO
CREATE USER Mirror_user FOR LOGIN Mirror_login
GO
CREATE CERTIFICATE Mirror_cert
AUTHORIZATION Mirror_cert
FROM FILE='C:certificateMirror_cert .cer' -----the Path of your Certificate After you
Copy it
GO
GRANT CONNECTON ENDPOINT:End mirroringTO[Mirror_login] -----Giveprivilege tothe User
Mirror_loginto connectto the MirroringEndpoint”End_Mirroring“
GO
4- Step No4 on Mirror Server:
Copythe Certificate”Principle_cert ”From Principle Servertothe Mirror Serverbecause Iwill Create
the Certificate PrincipleServeronMirroringServerWiththe Username Principle user
USE MASTER
GO
CREATE LOGIN Principle_login WITH PASSWORD='Admin123'
GO
CREATE USER Principle_user FOR LOGIN Principle_login
GO
CREATE CERTIFICATE Principle_cert
AUTHORIZATION Principle_cert
FROM FILE='C:certificateMirror_cert.cer' ---the Path of your Certificate After you Copy
it
GO
GRANT CONNECTON ENDPOINT::EndMirroring TO [Principle_login] ——-Giveprivilege tothe User
Principle_logintoConnecttothe Mirroring Endpoint”End_Mirroring “
28. Database Administration Community (https://mostafaelmasry.wordpress.com)
5- Step No5 on WitnessServer:Create master Key and Certificate Witness_Cert
USE MASTER
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD='Admin123'
GO
CREATE CERTIFICATE Witness_cert
WITH SUBJECT='Witness certificate'
GO
CREATE ENDPOINT End_Mirroring
STATE=STARTED
AS TCP (LISTENER_PORT= 5027,LISTENER_IP=ALL)
FOR DATABASE_MIRRORING
(AUTHENTICATION=CERTIFICATE Witness_cert,
ENCRYPTION = REQUIRED ALGORITHM RC4 , ROLE = Witness)
GO
BACKUP ERTIFICATE witness_cert
TO FILE='C:certificateWitness_cert.cer'
GO
6- Step No6 on Principle Server:
Copythe Certificate “Witness_cert ”From WitnessServertothe Principle Serverbecause Iwill Create
the Certificate WitnessServeronPrinciple ServerWiththe Username Witness_user
USE MASTER
GO
CREATE LOGIN Witness_login WITH PASSWORD='Admin123'
GO
CREATE USER Witness_user FOR LOGIN Witness_login
29. Database Administration Community (https://mostafaelmasry.wordpress.com)
GO
CREATE CERTIFICATE Witness_cert
AUTHORIZATION Witness_user FROM FILE='C:certificateWitness_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Witness_login]
GO
7- Step No7 on Mirror Server:
Copythe Certificate”Witness_cert”FromWitnessServertothe Mirror Serverbecause Iwill Create the
Certificate WitnessServeronMirror Serverwiththe Username Witness_user
USE MASTER
GO
CREATE LOGIN Witness_login WITH PASSWORD='Admin123'
GO
CREATE USER Witness_user FOR LOGIN Witness_login
GO
CREATE CERTIFICATE Witness_cert
AUTHORIZATION Witness_user FROM FILE='C:certificateWitness_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Witness_login]
GO
8- Step No8 on WitnessServer:
Copythe Certificate”Principle_cert ”From Principle Serverand ” Mirror_cert ” From the Mirror Server
” Principle_cert“
USE MASTER
GO
CREATE LOGIN Principle_login WITH PASSWORD='Admin123'
GO
CREATE USER Principle_user FOR LOGIN Principle_login
30. Database Administration Community (https://mostafaelmasry.wordpress.com)
GO
CREATE CERTIFICATE Principle_cert
AUTHORIZATION Principle_user
FROM FILE='D:certificatePrinciple_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Principle_login]
GO
” Mirror_cert “
CREATE LOGIN Mirror_login WITH PASSWORD=‘Admin123′
GO
CREATE USER Mirror_user FOR LOGIN Mirror_login
GO
CREATE CERTIFICATE Mirror_cert
AUTHORIZATION Mirror_user
FROM FILE='C:certificateMirror_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Mirror_login]
GO
9- take Full backup+ Log backupfrom yourDatabase Mirroringon Principle ServerthenGoto
MirroringServerand restore thisBackupWithNORECOVERYOption
10- GO TO the principle Serverinmake yourEasymirroringconfigurationbutinthe lastStepdon’t
write anyService AccountletitEmptythenAfterthisStepMirroringwill be Complete
Successfully
Thanks for all followers
Eng. Mustafa EL-Masry