Skip to content

Commit b3061d4

Browse files
authored
Refresh master database restore article (UUF 420834) (#33842)
1 parent 9fa81d9 commit b3061d4

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed
Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
2-
title: "Restore the master database (Transact-SQL)"
2+
title: "Restore the master Database (Transact-SQL)"
33
description: This article shows you how to restore the master database in SQL Server from a full database backup by using Transact-SQL.
44
author: MashaMSFT
55
ms.author: mathoma
6-
ms.date: "12/07/2022"
6+
ms.reviewer: randolphwest
7+
ms.date: 04/17/2025
78
ms.service: sql
89
ms.subservice: backup-restore
910
ms.topic: how-to
@@ -12,21 +13,21 @@ helpviewer_keywords:
1213
---
1314
# Restore the master database (Transact-SQL)
1415

15-
[!INCLUDE [SQL Server](../../includes/applies-to-version/sqlserver.md)]
16+
[!INCLUDE [SQL Server](../../includes/applies-to-version/sqlserver.md)]
1617

17-
This article explains how to restore the `master` database from a full database backup.
18+
This article explains how to restore the `master` database from a full database backup.
19+
20+
> [!WARNING]
21+
> 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 can result in undefined SQL Server instance behavior, with inconsistent feature support, and isn't guaranteed to be viable.
22+
23+
## Restore the `master` database
24+
25+
1. Start the server instance in single-user mode.
26+
27+
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](../../database-engine/configure-windows/database-engine-service-startup-options.md).
1828

19-
> [!WARNING]
20-
> 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.
21-
22-
### To restore the `master` database
23-
24-
1. Start the server instance in single-user mode.
25-
26-
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](../../database-engine/configure-windows/database-engine-service-startup-options.md).
27-
2829
From a command prompt, run the following commands, and make sure you replace `MSSQLXX.instance` with the appropriate folder name:
29-
30+
3031
```console
3132
cd C:\Program Files\Microsoft SQL Server\MSSQLXX.instance\MSSQL\Binn
3233
sqlservr -c -f -s <instance> -mSQLCMD
@@ -35,52 +36,51 @@ helpviewer_keywords:
3536
- The `-mSQLCMD` parameter ensures that only **sqlcmd** can connect to SQL Server.
3637
- For a default instance name, use `-s MSSQLSERVER`
3738
- `-c` starts SQL Server as an application to bypass Service Control Manager to shorten startup time
38-
39+
3940
If 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](../databases/rebuild-system-databases.md).
4041

41-
1. Connect to SQL Server using SQLCMD from another Command Prompt window
42+
1. Connect to SQL Server using **sqlcmd** from another command prompt window:
4243

4344
```console
44-
SQLCMD -S <instance> -E -d master
45+
sqlcmd -S <instance> -E -d master
46+
```
47+
48+
1. To restore a full database backup of `master`, use the following [RESTORE Statements](../../t-sql/statements/restore-statements-transact-sql.md)[!INCLUDE [tsql](../../includes/tsql-md.md)] statement:
49+
50+
```sql
51+
RESTORE DATABASE master FROM <backup_device> WITH REPLACE;
4552
```
4653

47-
1. To restore a full database backup of **master**, use the following [RESTORE DATABASE](../../t-sql/statements/restore-statements-transact-sql.md)[!INCLUDE[tsql](../../includes/tsql-md.md)] statement:
48-
49-
```sql
50-
RESTORE DATABASE master FROM <backup_device> WITH REPLACE
51-
```
52-
53-
The REPLACE option instructs [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] 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](../../tools/sqlcmd/sqlcmd-utility.md). For more information, see [Use the sqlcmd Utility](../../tools/sqlcmd/sqlcmd-use-utility.md).
54-
55-
> [!IMPORTANT]
56-
> After **master** is restored, the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] 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 &#40;SQL Server Configuration Manager&#41;](../../database-engine/configure-windows/scm-services-configure-server-startup-options.md).
54+
The `REPLACE` option instructs [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] 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](../../tools/sqlcmd/sqlcmd-utility.md). For more information, see [Use sqlcmd](../../tools/sqlcmd/sqlcmd-use-utility.md).
55+
56+
> [!IMPORTANT]
57+
> After `master` is restored, the instance of [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] shuts down and terminates the `sqlcmd` process. Before you restart the server instance, remove the single-user startup parameter. For more information, see [SQL Server Configuration Manager: Configure server startup options](../../database-engine/configure-windows/scm-services-configure-server-startup-options.md).
58+
59+
1. Restart the server instance normally as a service, without using any startup parameters.
5760

61+
1. Continue other recovery steps such as restoring other databases, attaching databases, and correcting user mismatches.
5862

59-
1. Restart the server instance normally as a service, without using any startup parameters.
60-
1. Continue other recovery steps such as restoring other databases, attaching databases, and correcting user mismatches.
61-
62-
## Example
63+
## Examples
6364

64-
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`.
65-
66-
> [!NOTE]
67-
> For a named instance, the **sqlcmd** command must specify the **-S**_\<ComputerName>_\\*\<InstanceName>* option.
65+
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`.
66+
67+
For a named instance, the **sqlcmd** command must specify the `-S<computer-name>\<instance-name>` option.
6868

6969
```console
70-
C:\> sqlcmd
71-
1> RESTORE DATABASE master FROM DISK = 'Z:\SQLServerBackups\master.bak' WITH REPLACE;
72-
2> GO
73-
```
74-
75-
## See Also
76-
77-
[Complete Database Restores &#40;Simple Recovery Model&#41;](../../relational-databases/backup-restore/complete-database-restores-simple-recovery-model.md)
78-
[Complete Database Restores &#40;Full Recovery Model&#41;](../../relational-databases/backup-restore/complete-database-restores-full-recovery-model.md)
79-
[Troubleshoot Orphaned Users &#40;SQL Server&#41;](../../sql-server/failover-clusters/troubleshoot-orphaned-users-sql-server.md)
80-
[Database Detach and Attach &#40;SQL Server&#41;](../../relational-databases/databases/database-detach-and-attach-sql-server.md)
81-
[Rebuild System Databases](../../relational-databases/databases/rebuild-system-databases.md)
82-
[Database Engine Service Startup Options](../../database-engine/configure-windows/database-engine-service-startup-options.md)
83-
[SQL Server Configuration Manager](../../relational-databases/sql-server-configuration-manager.md)
84-
[Back Up and Restore of System Databases &#40;SQL Server&#41;](../../relational-databases/backup-restore/back-up-and-restore-of-system-databases-sql-server.md)
85-
[RESTORE &#40;Transact-SQL&#41;](../../t-sql/statements/restore-statements-transact-sql.md)
86-
- [Start SQL Server in Single-User Mode](../../database-engine/configure-windows/start-sql-server-in-single-user-mode.md)
70+
C:\> sqlcmd
71+
1> RESTORE DATABASE master FROM DISK = 'Z:\SQLServerBackups\master.bak' WITH REPLACE;
72+
2> GO
73+
```
74+
75+
## Related content
76+
77+
- [Complete Database Restores (Simple Recovery Model)](complete-database-restores-simple-recovery-model.md)
78+
- [Complete Database Restores (Full Recovery Model)](complete-database-restores-full-recovery-model.md)
79+
- [Troubleshoot orphaned users (SQL Server)](../../sql-server/failover-clusters/troubleshoot-orphaned-users-sql-server.md)
80+
- [Database detach and attach (SQL Server)](../databases/database-detach-and-attach-sql-server.md)
81+
- [Rebuild system databases](../databases/rebuild-system-databases.md)
82+
- [Database Engine Service startup options](../../database-engine/configure-windows/database-engine-service-startup-options.md)
83+
- [SQL Server Configuration Manager](../../relational-databases/sql-server-configuration-manager.md)
84+
- [Back up and restore: System databases (SQL Server)](back-up-and-restore-of-system-databases-sql-server.md)
85+
- [RESTORE Statements (Transact-SQL)](../../t-sql/statements/restore-statements-transact-sql.md)
86+
- [Single-user mode for SQL Server](../../database-engine/configure-windows/start-sql-server-in-single-user-mode.md)

0 commit comments

Comments
 (0)