Saturday, December 7, 2013

Restore Master Database in SQL server

To restore the master database the server instance must be started in single user mode.

We cannot set master database in single user mode

alter database master set single_user

Msg 5058, Level 16, State 5, Line 1
Option 'MULTI_USER' cannot be set in database 'master'.


Stops SQL server agent or any other services except SQL server database engine

When restoring master database use same version otherwise you cannot restore master database. you should have proper backup of master database.

to start sql server in single user  instance mode. open configuration manager



Then select SQL Server Services node . select server instance. right click on properties.







go to advanced tab option select startup parameters. type -m; before this dD:\SQL server\MSSQL10.MALLSREDDY\MSSQL\DATA\master.mdf;

the startup parameters look like this 

-m;-dD:\SQL server\MSSQL10.MALLSREDDY\MSSQL\DATA\master.mdf;-eD:\SQL server\MSSQL10.MALLSREDDY\MSSQL\Log\ERRORLOG;-lD:\SQL server\MSSQL10.MALLSREDDY\MSSQL\DATA\mastlog.ldf





Then restart the instance. connect using sql server management studio (SSMS) without connecting object explorer as shown below




You Cannot open multiple windows while server is running in single user mode.

you will get the below error.

Login Failed for user xxxxx,reason server is in single user mode. Only one administrator can connect at a time.





Once you connect you can restore the master database using the command




Alternatively you can restore master database using sqlcmd mode also








Once you have restores master database.remove the startup parameter setting and restarts SQL Server


-dD:\SQL server\MSSQL10.MALLSREDDY\MSSQL\DATA\master.mdf;-eD:\SQL server\MSSQL10.MALLSREDDY\MSSQL\Log\ERRORLOG;-lD:\SQL server\MSSQL10.MALLSREDDY\MSSQL\DATA\mastlog.ldf




Once Restarted SQL Server service you can connect SQL Server as usal



No comments: