Starting SQL Server in single-user mode can be useful for performing maintenance tasks, such as restoring a master database, recovering from a disaster, or troubleshooting certain issues. Here’s how to start SQL Server in single-user mode:
Using SQL Server Configuration Manager
- Open SQL Server Configuration Manager:
- You can find SQL Server Configuration Manager in the Start menu or by searching for it.
- Stop the SQL Server Service:
- In SQL Server Configuration Manager, expand
SQL Server Services. - Right-click on the SQL Server instance you want to start in single-user mode (e.g.,
SQL Server (MSSQLSERVER)) and selectStop.
- Set the SQL Server Startup Parameters:
- Right-click on the SQL Server instance and select
Properties. - Go to the
Startup Parameterstab. - Add the parameter
-mto the list. This tells SQL Server to start in single-user mode. - Click
Addand thenOK.
- Start the SQL Server Service:
- Right-click on the SQL Server instance and select
Start.
Using Command Prompt
- Stop the SQL Server Service:
- Open Command Prompt with administrative privileges.
- Run the following command to stop the SQL Server service:
sh net stop MSSQLSERVER
For a named instance, use:sh net stop MSSQL$InstanceName
- Start SQL Server in Single-User Mode:
- Run the following command to start SQL Server in single-user mode:
sh net start MSSQLSERVER /m
For a named instance, use:sh net start MSSQL$InstanceName /m
Connecting to SQL Server in Single-User Mode
Once SQL Server is running in single-user mode, you can connect to it using SQL Server Management Studio (SSMS), sqlcmd, or any other SQL Server client. Only one connection is allowed, so make sure you are the only one connecting to the server.
Using SQL Server Management Studio (SSMS):
- Open SSMS.
- In the
Connect to Serverdialog, enter the server name. - Click
Connect.
Using sqlcmd:
- Open Command Prompt.
- Run the following command to connect to the server:
sqlcmd -S ServerName
Replace ServerName with the name of your SQL Server instance.
Performing Maintenance Tasks
While SQL Server is in single-user mode, you can perform various maintenance tasks, such as:
- Restoring the master database:
RESTORE DATABASE master FROM DISK = 'C:\Backup\master.bak' WITH REPLACE;
- Changing the server configuration or fixing issues:
ALTER DATABASE YourDatabase SET MULTI_USER;
Exiting Single-User Mode
After performing the necessary tasks, you can exit single-user mode by restarting SQL Server normally.
Using SQL Server Configuration Manager:
- Stop the SQL Server service.
- Remove the
-mparameter from the startup parameters. - Start the SQL Server service.
Using Command Prompt:
- Stop the SQL Server service:
net stop MSSQLSERVER
- Start the SQL Server service normally:
net start MSSQLSERVER
For a named instance, replace MSSQLSERVER with MSSQL$InstanceName.
Conclusion
Starting SQL Server in single-user mode is a powerful tool for performing critical maintenance tasks and troubleshooting. By following these steps, you can safely and effectively manage your SQL Server instance in single-user mode. Remember to revert to multi-user mode once your tasks are complete to ensure normal operation and accessibility for other users.