在SQL Server的資料庫維護過程中,有時候在一些特殊情況下需要在單用戶模式下啟動SQL Server實例。 下麵總結一下單用戶模式啟動SQL Server的幾種方式: 1:命令模式(sqlservr.exe)啟動 首先在命令視窗中切換到Binn目錄(這個要視SQL Server實際安裝路徑情況... ...
在SQL Server的資料庫維護過程中,有時候在一些特殊情況下需要在單用戶模式下啟動SQL Server實例。 下麵總結一下單用戶模式啟動SQL Server的幾種方式:
1:命令模式(sqlservr.exe)啟動
首先在命令視窗中切換到Binn目錄(這個要視SQL Server實際安裝路徑情況而定,另外,多實例情況下,必須切換到對應路徑),如果你對sqlservr.exe命令不熟悉,可以查看相關幫助信息。如下所示:
C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Binn>sqlservr.exe /?
usage: sqlservr
[-a<L2 buffer pool directory>,<size in GB>] (adding an L2 buffer pool file)
[-c] (not as a service)
[-d file] (alternative master data file)
[-l file] (alternative master log file)
[-e file] (alternate errorlog file)
[-f] (minimal configuration mode)
[-m] (single user admin mode)
[-g number] (stack MB to reserve)
[-k <decimal number>] (checkpoint speed in MB/sec)
[-n] (do not use event logging)
[-s name] (alternate registry key name)
[-T <number>] (trace flag turned on at startup)
[-x] (no statistics tracking)
[-y number] (stack dump on this error)
[-B] (breakpoint on error (used with -y))
[-K] (force regeneration of service master key (if exists))
[-v] (list version information)
See documentation for details.
2018-04-06 11:28:00.52 SQL Server shutdown has been initiated
sqlservr.ex啟動時,當前環境有多實例,而你有沒有指定參數-s,那麼就會提示類似如下信息, 需要你指定-s參數的SQL Server服務名稱。
C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Binn>sqlservr.ex
e -c -m
2018-04-06 11:40:54.15 Server Multiple instances of SQL server are installe
d on this computer. Renter the command, specifying the -s parameter with the nam
e of the instance that you want to start.
2018-04-06 11:40:54.16 Server SQL Server shutdown has been initiated
sqlservr.exe -c -m -s{instancename}
sqlservr.ex啟動時,如果SQL Server服務本身還在運行,就會報“Operating system error = 32(The process cannot access the file because it is being used by another process.).
C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Binn>sqlservr.ex
e -c -m -sMSSQLSERVER
2018-04-06 11:41:59.01 Server Error: 17058, Severity: 16, State: 1.
2018-04-06 11:41:59.01 Server initerrlog: Could not open error log file 'C:
\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Log\ERRORLOG'. Ope
rating system error = 32(The process cannot access the file because it is being
used by another process.).
2018-04-06 11:41:59.32 Server Error: 17058, Severity: 16, State: 1.
2018-04-06 11:41:59.32 Server initerrlog: Could not open error log file 'C:
\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Log\ERRORLOG'. Ope
rating system error = 32(The process cannot access the file because it is being
used by another process.).
2018-04-06 11:42:02.04 Server SQL Server shutdown has been initiated
如果在sqlservr.exe當中退出單用戶模式,直接使用CTRL+C 或 CTRL + Break,如下所示:
2:命令模式(net star)啟動
C:\Users>net stop mssqlserver
The following services are dependent on the SQL Server (MSSQLSERVER) service.
Stopping the SQL Server (MSSQLSERVER) service will also stop these services.
SQL Server Agent (MSSQLSERVER)
Do you want to continue this operation? (Y/N) [N]: y
The SQL Server Agent (MSSQLSERVER) service is stopping.
The SQL Server Agent (MSSQLSERVER) service was stopped successfully.
The SQL Server (MSSQLSERVER) service is stopping.
The SQL Server (MSSQLSERVER) service was stopped successfully.
C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Binn>net start mssqlserver /m
The SQL Server (MSSQLSERVER) service is starting.
The SQL Server (MSSQLSERVER) service was started successfully.
3:SQL Server配置管理器啟動
在SQL Server配置管理器中,找到對應實例,右鍵單擊屬性,在啟動參數裡面增加參數-m,然後重啟即可。
在單用戶模式下啟動SQL Server實例時,請註意下列事項:
· 只有一個用戶可以連接到伺服器。
· 不執行CHECKPOINT 進程。 預設情況下,啟動時自動執行此進程。