Как остановить ms sql server
Перейти к содержимому

Как остановить ms sql server

  • автор:

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 NET command from elevated Command Prompt (Run as Administrator).

net options

To start default SQL Server instance use following command:

To start named SQL Server instance use following command:

To stop default SQL Server instance use following command:

To stop named SQL Server instance use following command:

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 the systemctl command.

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

5 Ways to Stop or Start SQL Server Service

How to stop a local SQL Server instance from command line or PowerShell? In this tutorial we’ll show you 5 simple ways to stop or start SQL Server service in SQL Server 2016/2014/2012/2005.

Method 1: Stop / Start SQL Server Service from Microsoft Services Console

  1. Press the Windows + R keys to open the Run box. Type services.msc and press Enter.
  2. This will open the Microsoft Services console. Find the service called SQL Server (instant name) and then double-click on it.

sql-server-service

stop-sql-server-service

Method 2: Stop / Start SQL Server Service from Command Line

    .
    To stop a named SQL Server instance, type the following command. Replace SQLEXPRESS with the instance name.
    net stop MSSQL$SQLEXPRESS

start-sql-server-command-line

Method 3: Stop / Start SQL Server Service from SQL Server Configuration Manager

  1. To get started, you need to open SQL Server Configuration Manager. In Windows Server 2008 or 2003, you can click Start > Programs -> Microsoft SQL Server > Configuration Tools > SQL Server Configuration Manager.
  2. In the left pane of SQL Server Configuration Manager, click SQL Server Services. We can see all services in right pane. Right-click on SQL Server service and you can then select Stop or Start from the context menu.

sql-server-configuration-manager

Method 4: Stop / Start SQL Server Service from PowerShell

    .
    You can use the Start-Service cmdlet to stop your SQL Server service. Replace SQLEXPRESS with the instance name.
    Start-Service -Name ‘MSSQL$SQLEXPRESS’

start-sql-server-powershell

Method 5: Stop / Start SQL Server Service from SQL server Management Studio

  1. Open SQL server Management Studio and connect to your SQL Server instance.
  2. Right-click on the server in Object Explorer, you’ll have options to Stop, Start, Pause, Resume and Restart your SQL Server service. If we are not already connected, we can’t start a stopped instance.

Какой лучший способ запустить и остановить SQL Server из командной строки?

Мне нужно запустить и остановить SQL Server из командной строки. Я готов написать небольшую программу на C#, если это необходимо, но я подозреваю, что в настоящее время существует что-то (PowerShell, может быть?), Которое делает это изящно.

7 ответов

Чистый старт / стоп

Или в PowerShell, Stop-Service, Start-Service или Restart-Service. Обратите внимание, что все это должно быть сделано для каждого отдельного экземпляра, так же как и с другими предложениями здесь.

Для перезапуска SQL Server и агента SQL Server вы можете создать пакетный файл restartsql.bat со следующими командами, сохранить его и запустить при необходимости:

@ECHO OFF net stop «Агент SQL Server (MSSQLSERVER)» net stop MSSQLSERVER net start MSSQLSERVER net start «Агент SQL Server (MSSQLSERVER)»

Вот ответ, который на самом деле содержит немного бонусной информации. и более подробно отвечает на вопрос. Что если у вас более одного экземпляра SQL-сервера? Тогда вам нужно знать расширенный синтаксис NET START. Вы можете запускать службы по имени, а не только по имени службы (или тому, что mssqlserver является примером):

NET START «SQL Server (имя экземпляра)»

Это относится и к другим услугам. Хотите запустить службу уведомлений о системных событиях?

NET START «Служба уведомлений о системных событиях»

Бум идет динамитом! хе-хе

С помощью приведенных ниже команд я мог запускать и останавливать SQLServer 2019 Express:

Вы можете найти фактическое имя SQLServer в диспетчере конфигурации SQLServer , как показано ниже:

How Start/Stop MS SQL Server Using .bat file in windows

If you are a stack developer who works on multiple platform for coding, might face this proble of starting and stoping the Sql Server, because if you want work in default port 80 for apache in php of any other, you have to stop the iis and SQL server to run apache in port 80 only, so while doing this to start/stop we use eather SQL Configuration manager/ windows services. so here we will tell you how to create a .bat file to start and stop all the sql services at once.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *