sqlserver sa forgotten how to reset your password?

If you know of any other user passwords have sysadmin privileges, including enabling hybrid authentication windows account password. It is very simple, log in, directly modify the sa password.

If you do not know the password of any sysadmin privileges, but there are windows of the administrator account , you can reset the sa password.

Steps are as follows:

1. Start the instance of SQL Server in single-user mode (run as administrator rights cmd window)

C:\Windows\system32>net stop mssqlserver
SQL Server (MSSQLSERVER) 服务正在停止.
SQL Server (MSSQLSERVER) 服务已成功停止。

C:\Windows\system32>net start mssqlserver /m"SQLCMD"
SQL Server (MSSQLSERVER) 服务正在启动 .
SQL Server (MSSQLSERVER) 服务已经启动成功。

 

If not a single instance is started, use sqlcmd connection will encounter a similar error:

C:\Windows\system32>sqlcmd
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login failed for user 'xxx\xxxx’

 

2.  Use sqlcmd to trust log database , modify the sa password

In another cmd window using sqlcmd trust log database, parameter -E represents [-E trusted connection]

C:\Windows\system32>sqlcmd -E
1> alter login sa with password='xxx';
2> go

 

3. Enable the user sa

After resetting the finish will find sa is disabled, you need to enable

1> alter login sa enable;
2> go

Of course, you can create windows account the sysadmin role

C:\>sqlcmd -E
1> CREATE LOGIN [dba\mysa] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]
2> GO
1> ALTER SERVER ROLE [sysadmin] ADD MEMBER [xxx\xxx]
2> GO

Or SQL authentication account

C:\>sqlcmd -E
1> CREATE LOGIN [test1] WITH PASSWORD=N'Qw123456', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
2> GO

1> ALTER SERVER ROLE [sysadmin] ADD MEMBER [test1]
2> GO

 

4. Restart sqlserver in the normal way, you can log in

 

reference

https://www.cnblogs.com/kerrycode/p/8931386.html

Published 295 original articles · won praise 35 · views 80000 +

Guess you like

Origin blog.csdn.net/Hehuyi_In/article/details/103198774