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 NET
command from elevated Command Prompt (Run as Administrator).
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
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
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
To stop instance run following command:
sudo systemctl stop mssql-server
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>
To stop container run following command:
docker stop <container ID>
To restart container run following command:
docker restart <container ID>
-Marek
Share it: