QuickQuestion: How to start and stop SQL Server instance from a command line?

QuickQuestion series is a series of short posts in which I answer database related questions asked by my colleagues, friends, and co-workers, mainly application developers.

Today’s question:

How to start and stop SQL Server instance from a command line?

Windows

SQL Server instance as any other Windows network service can be managed using the NETcommand from elevated Command Prompt (Run as Administrator).

net options

To start default SQL Server instance use following command:

net start "SQL Server (MSSQLSERVER)"

or

net start MSSQLSERVER

To start named SQL Server instance use following command:

net start "SQL Server ( instancename )"

or

net start MSSQL$ instancename

SQLServer - net start

To stop default SQL Server instance use following command:

net stop "SQL Server (MSSQLSERVER)"

or

net stop MSSQLSERVER

To stop named SQL Server instance use following command:

net stop "SQL Server ( instancename )"

or

net stop MSSQL$ instancename

SQLServer - net stop

To restart instance you need to first stop it and then start it.  On Windows, there is no one single command that can be used for this purpose.

Linux (RHEL and Ubuntu)

On Linux, we don’t have yet named instances, so all commands are executed against default instance. SQL Server can be managed using thesystemctl command.

To check the current state of SQL Server instance you can run this command:

sudo systemctl status mssql-server

To start instance run following command:

sudo systemctl start mssql-server

SQLServer - systemctl start

To stop instance run following command:

sudo systemctl stop mssql-server

SQLServer - systemctl stop

To restart instance run following command:

sudo systemctl restart mssql-server
Docker

Docker provides us a very similar set of commands.

To start container run following command:

docker start <container ID>

SQLServer - docker start

To stop container run following command:

docker stop <container ID>

SQLServer - docker stop

To restart container run following command:

docker restart <container ID>

-Marek

Share it:
FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close