Events
31 Mar, 11 pm - 2 Apr, 11 pm
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
This article explains how to restore the master
database from a full database backup.
Warning
In the event of disaster recovery, the instance where the master
database is being restored to should be as close to an exact match to the original as possible. At a minimum, this recovery instance should be the same version, edition, and patch level, and it should have the same selection of features and the same external configuration (hostname, cluster membership, and so on) as the original instance. Doing otherwise might result in undefined SQL Server instance behavior, with inconsistent feature support, and is not guaranteed to be viable.
Start the server instance in single-user mode.
You can start SQL Server by either using the -m
or -f
startup parameters. For more information about startup parameters, see Database Engine Service Startup Options.
From a command prompt, run the following commands, and make sure you replace MSSQLXX.instance
with the appropriate folder name:
cd C:\Program Files\Microsoft SQL Server\MSSQLXX.instance\MSSQL\Binn
sqlservr -c -f -s <instance> -mSQLCMD
-mSQLCMD
parameter ensures that only sqlcmd can connect to SQL Server.-s MSSQLSERVER
-c
starts SQL Server as an application to bypass Service Control Manager to shorten startup timeIf the SQL Server instance can't start due to a damaged master
database, you must rebuild the system databases first. For more information, see Rebuild system databases.
Connect to SQL Server using SQLCMD from another Command Prompt window
SQLCMD -S <instance> -E -d master
To restore a full database backup of master, use the following RESTORE DATABASETransact-SQL statement:
RESTORE DATABASE master FROM <backup_device> WITH REPLACE
The REPLACE option instructs SQL Server to restore the specified database even when a database of the same name already exists. The existing database, if any, is deleted. In single-user mode, we recommend that you enter the RESTORE DATABASE statement in the sqlcmd utility. For more information, see Use the sqlcmd Utility.
Important
After master is restored, the instance of SQL Server shuts down and terminates the sqlcmd process. Before you restart the server instance, remove the single-user startup parameter. For more information, see Configure Server Startup Options (SQL Server Configuration Manager).
Restart the server instance normally as a service, without using any startup parameters.
Continue other recovery steps such as restoring other databases, attaching databases, and correcting user mismatches.
The following example restores the master
database on the default server instance. The example assumes that the server instance is already running in single-user mode. The example starts sqlcmd
and executes a RESTORE DATABASE
statement that restores a full database backup of master
from a disk device: Z:\SQLServerBackups\master.bak
.
Note
For a named instance, the sqlcmd command must specify the -S<ComputerName>\<InstanceName> option.
C:\> sqlcmd
1> RESTORE DATABASE master FROM DISK = 'Z:\SQLServerBackups\master.bak' WITH REPLACE;
2> GO
Complete Database Restores (Simple Recovery Model)
Complete Database Restores (Full Recovery Model)
Troubleshoot Orphaned Users (SQL Server)
Database Detach and Attach (SQL Server)
Rebuild System Databases
Database Engine Service Startup Options
SQL Server Configuration Manager
Back Up and Restore of System Databases (SQL Server)
RESTORE (Transact-SQL)
Events
31 Mar, 11 pm - 2 Apr, 11 pm
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Back up and restore your Azure SQL database - Training
Learn how to protect the data in your Azure SQL database and recover from data loss or corruption with backup and restore.
Certification
Microsoft Certified: Azure Database Administrator Associate - Certifications
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.
Documentation
Rebuild system databases - SQL Server
System databases must be rebuilt to fix corruption problems in the master, model, msdb, or resource system databases, or to modify the default server-level collation.
Back up and restore: System databases - SQL Server
SQL Server maintains system databases essential for operation of a server instance. Several system databases must be backed up after every significant update.
MSSQLSERVER_3417