博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL Server 2012笔记分享-39:重建master数据库
阅读量:6847 次
发布时间:2019-06-26

本文共 3487 字,大约阅读时间需要 11 分钟。

===================================================================

(一)重建master

   

当master数据库被破坏或者SQL server服务无法启动时,我们可能需要重建master,具体可以参考下面的英文注释信息。

首先对master数据库做好数据备份。

其次我删除master里面的系统表,模拟master崩溃。

Rebuilding the Master Database

You will need to rebuild an entirely new version of the master database if:

? The master database is severely damaged, and the SQL Server instance will not restart.

? A current backup of master is not available.

To rebuild the master database, run the SQL Server setup from the command prompt. The setup.exe executable is used to install SQL Server, upgrade from previous SQL Server instance, uninstall SQL Server, and to rebuild the master database. The attributes used for using to rebuild the system databases with descriptions are as follows:

? /QUIET – Specifies that the setup will not display

? /ACTION=REBUILDDATABASE – Specifies a setup workflow, such as INSTALL, UNINSTALL, or UPGRADE. This is a required parameter. In this case, it is being used to rebuild the master database.

? /INSTANCENAME=<instance_name> – Specifies a default or named instance. MSSQLSERVER is the default install for non-Express editions. This parameter is required when installing the SQL Server Database Engine (SQL), Analysis Services (AS), or Reporting Services (RS).

? /SQLSYSADMINACCOUNTS = <accounts> – Specifies the Windows account(s) to provision as SQL Server system administrators.

? /SAPWD= <password> – Specifies the password for the sa, sysadmin account.

? /SQLCOLLATION=<collation_name> – Specifies a Windows or SQL Server collation to use for the Database Engine

You can rebuild the system database for a default instance by using the following T-SQL syntax:

setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=‘<instance name>’ /SQLSYSADMINACCOUNTS=‘<DomainName\Username>’ /SAPWD =‘<password>’

然后使用下面的命令对master数据库进行修复。下图中使用的是AD账户。

Once the rebuild is complete, you can restore your original version to the server if a backup is available, by using the steps to restore the master database. If no backup is available, you will need to manually re-create and reconfigure your system. Rebuilding the system databases includes rebuilding the msdb and model databases, so you should ensure that you have backup copies of your versions to restore, following the rebuild.

The log files from the rebuild can be found in the ..110\setup bootstrap\logs directory. The Summary.txt file will show from a high level whether the rebuild was successful and will point to more detailed logs if there were any errors. This file represents the most recent summary of an execution setup. You need to look for a folder inside the logs directory that matches the datetime when you run setup to rebuild the system databases.

重建完成后,可以看到master的系统表都回来了。

(二)恢复master备份

重建完成后,可以继续还原master的备份。

首先要让数据库处于单用户模式,可以修改SQL server的服务,在启动参数加上-m;

然后再进入sqlcmd里面,输入下面的master还原的命令。

sqlcmd

1>restore database master from disk='d:/fullbackup/fullbackup.bak' with replace;

2>go

注意:

   

如果当初安装SQL2012的时候是RTM版本,然后升级到了SQL 2012 SP1,那么在重建master数据库的时候要使用SQL 2012 SP1的安装光盘,如果你使用SQL 2012 RTM的镜像光盘来重建SQL 2012 SP1的master数据库,那么在恢复master备份的时候会失败,会提示master版本和备份中的版本不一致。

==================================================================

下面是一篇重建master的文章

====================================================================

2014年7月18日更正

在服务的启动模式添加M参数,正规的方法应该是打开SQL server configuration manager里面停用SQL server服务,然后再加参数,最好不要像上面文中写的直接在services.msc服务管理器中修改。

=====================================================================

转载地址:http://wzoul.baihongyu.com/

你可能感兴趣的文章
绘图、Core Animation与硬件架构
查看>>
MySQL字符集及校对规则的理解
查看>>
《打造七星级团队》观后感
查看>>
Odoo(OpenERP)开发实践:数据模型学习
查看>>
正则表达式规则
查看>>
HDU 5344(MZL&#39;s xor-(ai+aj)的异或和)
查看>>
HDU 4782 Beautiful Soup(模拟)
查看>>
怎么样才算是精通 C++?
查看>>
P2661 信息传递
查看>>
从Freelancer的热门Skill看看你应该学什么?
查看>>
做互联网服务的一些心得碎语
查看>>
几种不同类型的消息队列
查看>>
ssh2项目整合 struts2.1+hibernate3.3+spring3 基于hibernate注解和struts2注解
查看>>
(转)RabbitMQ学习之Headers交换类型(java)
查看>>
2017.7.15清北夏令营精英班Day1解题报告
查看>>
UML之状态图
查看>>
python 的日志logging模块
查看>>
Swift开发教程--使用Storyboard进行界面跳转
查看>>
nmon使用
查看>>
svn删除文件或文件夹后提交失败及解决
查看>>