Forgot SQL Server Password

后端 未结 6 1011
无人及你
无人及你 2020-12-05 05:19

I installed SQL Server 2005 sometime ago and forgot the administrator password I set during setup. How can I connect to SQL server now?

EDIT: I thin

6条回答
  •  日久生厌
    2020-12-05 05:52

    For these steps to work, you need to be an admin on box where SQL Server is installed.

    • Stop SQL Server from configuration manager
    • Start SQL Server in single user mode
    • Add this -mSQLCMD command as one of the start up parameters, by right clicking the service and going into startup parameters section as shown in screenshot below and start SQL Server

    • Now connect to SQLSERVER from SQLCMD (open command prompt as admin) like below:

      sqlcmd -s servername\instancename
      

      And run below command:

      USE [master]
      GO
      CREATE LOGIN [BUILTIN\Administrators] FROM WINDOWS WITH DEFAULT_DATABASE=[master]
      GO
      EXEC master..sp_addsrvrolemember @loginame = N'BUILTIN\Administrators', @rolename = N'sysadmin'
      GO
      

      Above command adds all local users as sysadmins. You may change this and add a user like or you can make another user sysadmin and remove BUILTIN\Administrators

    • Once this is done, you need to now stop SQL Server and remove -mSQLCMD parameter and restart SQL Server

    References:
    Help : I lost sa password and no one has System Administrator (SysAdmin) permission. What should I do?

提交回复
热议问题