SQL Server – Cannot Recover the Master Database

Was recently patching my SQL Server 2014 instance with Service Pack 2 in my lab, when I noticed I couldn’t start SQL Server post patching installation.

As i couldnt start SQL Server, i couldnt check the SQL Server Logs. Luckily i remembered that the SQL logs are physically stored where the SQL Server binaries are kept.

Found the Error.log under
D:\Program Files\Microsoft SQL Server\MSSQL10_50.VMWare\MSSQL\Log

MasterDatabaseCorrupt#1

Looks like the database is corrupted. Cannot recover the master database isnt a great message.

MasterDatabaseCorrupt#2

Normally I would restore the system database from backup, but in this case I was in an environment that didn’t have any backups available.

Solution:

To resolve, we need to rebuild the master database.

Pre-Reqs:

  1. SA password is known;
  2. SA account is enabled;
  3. SQL Server installation media for the particular SQL version is mounted.

To rebuild the master database we need to run the below command in an elevated command prompt:

  1. Navigate to the setup.exe is within the installation media.

          CD E:

  1. Now run the command to rebuild the database.
    ./setup /ACTION=REBUILDDATABASE /INSTANCENAME=<instance_name> /SQLSYSADMINACCOUNTS=<admin_account> /SAPWD=<sa_password>

You should now be able to start SQL Server with no issues.

 

Error – Cannot Recover the Master Database. SQL Server Is Unable To Run.

Recently had to install Full-Text to an existing SQL Server 2008 R2 install  for an application when all of a sudden the feature fails to install.
Weird.

Checked SQL Server Management Studio. Couldnt connect. Rebooted. No luck.

You can check the error logs if you navigate to where the SQL Server binaries are located in this location which was what I proceeded to do:
%Program-Files%\Microsoft SQL Server\MSSQL.1MSSQL\LOG\ERRORLOG

Opened the latest error log in notepad and found the below error in the file:

RecoverMasterDB#1

Solution:

Restore from backup. But incase you dont, heres how you fix it:

Navigate to C:\Program Files\Microsoft SQL Server\MSSQL\binn where the SQL Server executable is located.

Run the following command:

Note the following variables to switch out in the script:

<Instance_Name>
<SysAdminAccount>
<password>

.\setup /ACTION=REBUILDDATABASE /INSTANCENAME=<Instance_Name>  /SQLSYSADMINACCOUNTS=<SysAdminAccount> /SAPWD=<Password>

Once the command has been run, you should now be able to open SQL Server Management Studio.

This method will detach the databases, but will not delete any of the files. Reattach the databases using the MDF and LDF files.
Restart your application services.