场景 :这是一个命名实例,使用动态端口,需要进入单用户模式进行维护。 一、启动实例 我们将直接使用命令行窗口启动单用户模式。 1. 找到 sqlservr.exe 的路径 在Windows的“服务”中找到这个命名实例,查出“可执行文件的路径”。例如: "C:\Program Files
场景:这是一个命名实例,使用动态端口,需要进入单用户模式进行维护。
一、启动实例
我们将直接使用命令行窗口启动单用户模式。
1. 找到 sqlservr.exe 的路径
在Windows的“服务”中找到这个命名实例,查出“可执行文件的路径”。例如:
"C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008R2\MSSQL\Binn\sqlservr.exe" -sSQL2008R2
2. 启动实例
打开一个命令行窗口。将“可执行文件的路径”复制到这个命令行窗口,然后添加“ -m "sqlcmd" ” 参数,指定单用户模式启动而且只有 sqlcmd 可以连接到这个实例。
C:\Users\Administrator> "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008R2\MSSQL\Binn\sqlservr.exe" -sSQL2008R2 -m "sqlcmd" |
启动后,这个窗口将显示一大堆的启动信息。
注意:为了保证启动帐户有足够的权限,建议改为 Local System 启动。请在 SQL Server 配置管理器中修改。
二、确认端口配置
针对 TCP/IP 端口,面临两种选择。一种是统一配置本机所有的 IP 的端口,另一种是单独为本机每个 IP 地址配置端口。
1. 选择1:启用“全部侦听”
在前面的步骤中,在命令行窗口中注意寻找端口信息。例如:
2015-01-07 10:42:49.09 服务器 Server is listening on [ 'any' 2015-01-07 10:42:49.09 服务器 Server is listening on [ 'any' 2015-01-07 10:42:49.10 服务器 Server local connection provider is ready to accept connection on [ \\.\pipe\SQLLocal\SQL2008R2 ]. 2015-01-07 10:42:49.11 服务器 Server local connection provider is ready to accept connection on [ \\.\pipe\MSSQL$SQL2008R2\sql\query ]. 2015-01-07 10:42:49.11 服务器 Server is listening on [ ::1 2015-01-07 10:42:49.11 服务器 Server is listening on [ 127.0.0.1 2015-01-07 10:42:49.12 服务器 Dedicated admin connection support was established for listening locally on port 49163. |
注意:由于每个实例的配置不尽相同,所以不一定都会看到本例完全一样的信息。“Server is listening on [ 'any'
一旦“全部侦听”启用了,那么就只有最底下一栏“IPAll”生效,其它的IP单独的配置都无效!
说明:
(1)“TCP动态端口”如果留空,表示使用静态端口;如果在配置时设置为0,表示使用动态端口。使用动态端口时,在实例启动之后,才会显示当前的端口。每次重启实例都可能换成另一个端口。
(2)如果在“TCP端口”中填写一个固定的数据,同时将“TCP动态端口”留空,那么重启后,实例将使用这个静态端口。对于服务器上的默认实例,默认使用 TCP1433 端口。
2. 选择2:不启用“全部侦听”
下面的信息则显示只侦听127.0.0.1端口。
2015-01-07 11:03:53.76 服务器 Server is listening on [ 127.0.0.1 2015-01-07 11:03:53.77 服务器 Dedicated admin connection support was established for listening locally on port 49168. |
在配置界面,仅针对127.0.0.1这个IP,将“活动”和“已启用”都设为“是”。可以分别为每个IP配置不同的端口以及设置端口的活动状态。
故障排除:
如果本机曾经修改过IP地址,导致在不启用“全部侦听”时会将错误的旧IP地址绑定到该实例,这样会报错并导致启动失败。请参考 《修改 SQL Server 服务器的 IP 地址》 http://jimshu.blog.51cto.com/3171847/1120377
三、客户端连接
由于前面的步骤仅允许使用 SQLCMD 方式连接,所以需要另外打开一个命令行窗口。使用“-S”参数,后面加上IP地址以及端口号(两者之间用逗号隔开)。例如,下面的命令已经成功地建立了连接。
C:\Users\Administrator> sqlcmd -S 127.0.0.1,49163 1> |
连接成功后,即可参考《忘记管理员密码的补救办法》 http://jimshu.blog.51cto.com/3171847/1563207 进行一些维护操作。例如,重设sa的密码。
1> Alter Login [sa] with password='newpassword'; 2> GO |
注:在本例中,我们直接使用端口号。如果使用实例名(127.0.0.1\SQL2008R2),那么还需要启用 SQL Server Browser服务,并为防火墙打开 UDP1434 端口。请参考《SQL Server 客户端连接的问题》 http://jimshu.blog.51cto.com/3171847/1395199
四、停止实例
在启动实例的那个命令行窗口,使用 Ctrl-C 或者 Ctrl-Break 组合键,停止实例。
Do you wish to shutdown SQL Server (Y/N)? y 2015-01-07 11:36:37.76 spid7s SQL Server shutdown due to Ctrl-C or Ctrl-Break signal. This is an informational message only. No user action is required. 2015-01-07 11:36:37.76 spid7s SQL Trace was stopped due to server shutdown. Trace ID = '1'. This is an informational message only; no user action is required. |
甚至,可以直接关闭这个命令行窗口。

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools
