单用户模式启动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 进程。 默认情况下,启动时自动执行此进程。
在单用户模式下启动 SQL Server 可使计算机本地 Administrators 组的任何成员作为 sysadmin 固定服务器角色的成员连接到 SQL Server 实例。 有关详细信息,请参阅在系统管理员被锁定时连接到 SQL Server。
在单用户模式下, 只有一个用户可以连接到服务器,那么这样问题就来了,很有可能当你需要登录的时候,这个唯一的的用户已经被其它用户捷足先登了。此时你却被拒之门外,是否相当抓狂。此时你可能遇到下面错误
C:\Users>sqlcmd
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login failed for user '
xxxx'. Reason: Server is in single user mode. Only one administrator c
an connect at this time..
SSMS客户端一般遇到下面这样的错误信息:
Login failed for user 'xxxx'. Reason: Server is in single user mode. Only one administrator can connect at this time. (Microsoft SQL Server, Error: 18461)
错误日志或命令里面输出的日志,你会看到类似如下信息:
2018-04-06 12:21:14.85 Logon Error: 18461, Severity: 14, State: 1.
2018-04-06 12:21:14.85 Logon Login failed for user 'xxx'. Reason: Server is in single user mode. Only one administrator can connect at this time. [CLIENT: 192.168.xxx.xxx]
在这种情况下,怎么办呢? 难道要拼速度? 当然不是,你需要从下面这些方面注意:
在单用户模式下连接到SQL Server实例之前,停止SQL Server Agent 服务;否则 SQL Server Agent 服务将使用该连接,从而使其阻塞。
在单用户模式下启动SQL Server实例时,SQL Server Management Studio 可以连接到 SQL Server。 但是Management Studio中的对象资源管理器可能会失败,因为在某些操作中它需要使用多个连接。 若要在单用户模式下管理 SQL Server,可以执行 Transact-SQL 语句(仅通过 Management Studio 中的查询编辑器连接)或者使用 sqlcmd 实用工具。
当您将 -m 选项与 sqlcmd 或 Management Studio 结合使用时,可以将连接限制为指定的客户端应用程序。 例如,-m"sqlcmd" 将连接限制为单个连接并且该连接必须将自身标识为 sqlcmd 客户端程序。 当您正在单用户模式下启动 SQL Server 并且未知的客户端应用程序正在占用这个唯一的可用连接时,使用此选项。 若要通过 Management Studio 中的查询编辑器进行连接,请使用 -m"Microsoft SQL Server Management Studio - Query"。
如下所示,如果你指定了单用户只能以SQLCMD连接,那么此时,其它通过SSMS等其它方式连接数据库都会报上面错误,其它通过程序连接过来的连接就不会抢占这个连接了。
C:\Windows\system32>net stop mssqlserver
The SQL Server (MSSQLSERVER) service is stopping.
The SQL Server (MSSQLSERVER) service was stopped successfully.
C:\Windows\system32>net start mssqlserver /m"SQLCMD"
The SQL Server (MSSQLSERVER) service is starting.
The SQL Server (MSSQLSERVER) service was started successfully.
C:\Windows\system32>

如果你指定参数/m"Microsoft SQL Server Management Studio - Query" 那么就会阻止像应用程序或SQLCMD登录,如下所:
C:\Windows\system32>net stop mssqlserver
The SQL Server (MSSQLSERVER) service is stopping.
The SQL Server (MSSQLSERVER) service was stopped successfully.
C:\Windows\system32>net start mssqlserver /m"Microsoft SQL Server Management Studio - Query"
The SQL Server (MSSQLSERVER) service is starting.
The SQL Server (MSSQLSERVER) service was started successfully.
C:\Users>sqlcmd
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login failed for user '
xxx'. Reason: Server is in single user mode. Only one administrator c
an connect at this time..

单用户模式启动SQL Server实例总结的更多相关文章
- SQL server已经设置为单用户模式,Sql server还原失败数据库正在使用,无法获得对数据库的独占访问权
如果已经设置为单用户模式,还是报这个错误的话,就按照一下SQL执行就
- 专用管理连接(DAC)和单用户模式
数据库运维人员,在维护数据库时,有时会遇到一些特殊的情况,例如,SQL Server实例无法访问,此时需要用到管理员在紧急情况下专用的连接:有时,在做一些系统级别的配置修改时,当前数据库不能被其他用户 ...
- SQL server已经设置为单用户模式,还是无法做分离、属性设置等操作
https://www.cnblogs.com/xingyunqiu/p/10336938.html SQL server已经设置为单用户模式,Sql server还原失败数据库正在使用,无法获得对数 ...
- SQL SERVER的单用户模式以及专用管理员连接
2007-03-08 18:22:03.46 server Microsoft SQL Server 2000 - 8.00.2039 (Intel X86) May 3 2005 23:1 ...
- 最小配置启动SQL SERVER,更改SQL Server最大内存大小导致不能启动的解决方法
如果存在配置问题而无法启动服务器,则可以使用最小配置启动选项来启动 Microsoft SQL Server 实例. 这就是启动选项 -f. 使用最小配置启动 SQL Server 实例会自动将服务器 ...
- 修改sql server实例、数据库、表、字段的排序规则
转自:http://blog.51cto.com/jimshu/1095780 概念与详情请参考:字符编码与排序规则:https://www.cnblogs.com/gered/p/9145123.h ...
- Linux学习之CentOS(二十二)--单用户模式下修改Root用户的密码
在上一篇随笔里面详细讲解了Linux系统的启动过程 (Linux学习之CentOS(二十一)--Linux系统启动详解),我们知道Linux系统的启动级别一共有6种级别,通过 /etc/inittab ...
- centos7.2进入单用户模式
1 - 在启动grub菜单,选择编辑选项启动 2 - 按键盘e键,来进入编辑界面 3 - 找到Linux 16的那一行,将ro改为rw init=/sysroot/bin/sh 4 - 现在按下 Co ...
- 在Linux 中进入单用户模式的技巧
在这篇简短的文章中,我们将向你介绍在 SUSE 12 Linux 中进入单用户模式的步骤.在排除系统主要问题时,单用户模式始终是首选.单用户模式禁用网络并且没有其他用户登录,你可以排除许多多用户系统的 ...
随机推荐
- Cookie登录保存
Login.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Log ...
- Go语言远程执行ssh命令简单封装(支持带交互命令)
使用包:golang.org/x/crypto/ssh 以下封装一个发送命令的Cli结构体 type Cli struct { IP string //IP地址 Username string //用 ...
- Spring Boot (二)集成Jsp与生产环境部署
一.简介 提起Java不得不说的一个开发场景就是Web开发,也是Java最热门的开发场景之一,说到Web开发绕不开的一个技术就是JSP,因为目前市面上仍有很多的公司在使用JSP,所以本文就来介绍一下S ...
- win8 notepad++ 设置无法保存
前些天买了新笔记本.装的是win8 ,后来装了notepad++ ,最新版的,改了字体,下次从新打开之后,发现字体改动无效.后来试了一下“管理员身份运行”,再次打开,保存就有效.但总不能每次都那样去右 ...
- μC/OS-II 任务堆栈的初始化
任务堆栈的作用 应用程序在创建一个新任务的时候,必须把在系统启动这个任务时 CPU 各寄存器所需要的初始数据(任务指针.任务堆栈指针.程序状态字等等),事先存放在任务的堆栈中,以备任务切换等操作时调用 ...
- Python图像处理之验证码识别
在上一篇博客Python图像处理之图片文字识别(OCR)中我们介绍了在Python中如何利用Tesseract软件来识别图片中的英文与中文,本文将具体介绍如何在Python中利用Tesseract ...
- 编译部署mysql5.7.13
署环境centos7.2+mysql5.7.131.依赖包注: 相关依赖包的作用cmake:由于从 MySQL5.5 版本开始弃用了常规的 configure 编译方法,所以需要 CMake 编译器, ...
- 蓝桥杯试题----- 打印大X
打印大X 小明希望用星号拼凑,打印出一个大X,他要求能够控制笔画的宽度和整个字的高度.为了便于比对空格,所有的空白位置都以句点符来代替. 要求输入两个整数m n,表示笔的宽度,X的高度.用空格分开(0 ...
- C#设计模式之十八状态模式(State Pattern)【行为型】
一.引言 今天我们开始讲“行为型”设计模式的第六个模式,该模式是[状态模式],英文名称是:State Pattern.无论是现实世界,还是面向对象的OO世界,里面都有一个东西,那就是对象.有对象当然就 ...
- 使用typeof()或者typeof数据类型检测
使用typeof()或者typeof进行基本数据类型检测( typeof(X)等于typeof X 返回的是数据类型) 数据类型有:基本数据类型,字符串(string),布尔值(true/fals ...