zoukankan      html  css  js  c++  java
  • 使用DOS工具修复数据库

    当SQL Server 实例出现异常,无法远程链接时,数据库管理员需要登陆到SQL Server实例机器上,通过命令行工具,修复异常。

    一,使用net命令行启动数据库

    通过net start 命令启动SQL Server服务,服务名是mssqlserver,命令如下:

    net start MSSQLSERVER

    可以在启动时,添加启动参数(startup option),使用“/”代替“-”:

    net start MSSQLSERVER /f /m

    二,SQL Server服务的启动参数

    SQL Server的启动参数:

    • -f :Starts an instance of SQL Server with minimal configuration. This is useful if the setting of a configuration value (for example, over-committing memory) has prevented the server from starting.

    参数-f :指定以最小化配置启动SQL Server服务,

    • -T trace#:Indicates that an instance of SQL Server should be started with a specified trace flag (trace#) in effect. Trace flags are used to start the server with nonstandard behavior. 

     参数 -T:指定SQL Server使用特定的追踪标志(Trace Flag)启动,追踪标志(Trace Flag)能够使SQL Server临时处于特殊的行为,便于DBA进行故障排除。

     三,追踪标志

    追踪标志(Trace Flag)用于把SQL Server临时切换到特殊的状态。

    1,3608 以最小化配置启动

    3608:在SQL Server启动时,除了master数据库之外,阻止自动启动和还原其他数据库。对于系统数据库,如果需要初始化tempdb,那么SQL Server会还原model数据库,用于创建tempdb数据库。对于用户数据库,在用户访问时启动和还原。

    通常情况下,-T3608 和 -f 参数一起使用,表示以最小化配置启动SQL Server示例:

    NET START MSSQLSERVER /f /T3608

    2,902 修复在脚本升级模式下遇到的错误

    902:在启动数据库服务时,绕过(bapass)数据库内部升级脚本的执行。当安装更新时,如果事件查看器抛出以下错误,可以使用902标志临时修复。

    Script level upgrade for database 'master' failed because upgrade step 'msdb110_upgrade.sql' encountered error 226, state 6, severity 16. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion.

    警告:此跟踪标志用于在脚本升级模式期间对失败更新进行故障诊断,并且不支持在生产环境中连续运行它。 数据库升级脚本需要成功执行完整安装的累积更新和Service Pack。 不这样做可能会导致您的SQL Server实例出现意外问题。

    当出现该错误时,在本地模式下,使用net 命令启动SQL Server服务:

    net start MSSQLSERVER /T902

    也可以在SQL Server配置管理器中,向启动(startup)参数中增加-T902,每次SQL Server服务启动时,都会自动以902标志启动:

    四,sqlcmd工具

    登陆到SQL Server实例的主机,打开DOS命令行窗口,使用sqlcmd工具连接SQL Server实例,

    sqlcmd -A -E

    以专用管理员链接登陆SQL Server实例,然后,执行响应的查询,排除故障。

    五,添加权限

    当管理员有主机(Host)的权限,而没有SQL Server实例的权限时,管理员可以通过DOS命令为自己添加权限。

    首先,以单例模式开始SQL Server实例:

    net stop mssqlserver
    net start MSSQLSERVER /f /m

    其次,登陆到SQL Server实例:

    sqlcmd -A -E

    然后,创建Login,授予权限,作为DBA,应该授予最高的系统管理的权限。

    create login [domain
    ame] 
    from windows;
    go
    
    alter server role sysadmin
    add member [domain
    ame] ;
    go

    最后,以多用户模式重启SQL Server服务:

    net stop mssqlserver
    net start MSSQLSERVER

    参考文档:

    Use Trace Flag 902 to Recover from a Cumulative Update Failure

    Moving System Databases

    Using the SQL Server Service Startup Options

    How to: Start an Instance of SQL Server (net Commands)

    Trace Flags (Transact-SQL)

    sqlcmd Utility

  • 相关阅读:
    Memcached简介
    TP5 volist
    Getting command line access to PHP and MySQL running MAMP on OSX
    PHP use
    PHP 命名空间(namespace)
    mac 使用 pf 做端口转发
    微信测试帐号如何设置URL和Token,以及相关验证的原理
    ionic开发笔记
    Eclipse下配置Maven
    css引用第三方字体库
  • 原文地址:https://www.cnblogs.com/ljhdo/p/4538311.html
Copyright © 2011-2022 走看看