“数据库镜像”是一种提高 SQL Server 数据库的可用性的解决方案。镜像基于每个数据库实现,并且只适用于使用完整恢复模式的数据库。数据库镜像维护一个数据库的两个副本,这两个副本必须驻留在不同的 SQL Server 数据库引擎 服务器实例上。通常,这些服务器
“数据库镜像”是一种提高 SQL Server 数据库的可用性的解决方案。 镜像基于每个数据库实现,并且只适用于使用完整恢复模式的数据库。数据库镜像维护一个数据库的两个副本,这两个副本必须驻留在不同的 SQL Server 数据库引擎 服务器实例上。 通常,这些服务器实例驻留在不同位置的计算机上。 启动数据库上的数据库镜像操作时,在这些服务器实例之间形成一种关系,称为“数据库镜像会话”。其中一个服务器实例使数据库服务于客户端(“主体服务器”), 另一个服务器实例则根据镜像会话的配置和状态,充当热备用或温备用服务器(“镜像服务器”)。 具有自动故障转移功能的高安全性模式要求使用第三个服务器实例,称为“见证服务器”。
主体服务器 (principal server)
在数据库镜像中,是指当前作为主体数据库的数据库所属于的伙伴。
镜像服务器 (mirror server)
在数据库镜像配置中,镜像数据库所在的服务器实例。
见证服务器 (Witness)
仅用于高安全性模式,SQL Server 的一个可选实例,它能使镜像服务器识别何时要启动自动故障转移。 与这两个故障转移伙伴不同的是,见证服务器并不能用于数据库。 见证服务器的唯一角色是支持自动故障转移。
所有数据库镜像会话都只支持一台主体服务器和一台镜像服务器。 下图显示了该配置:
下图显示了包含见证服务器的配置:
更多关于SQL数据库镜像概念请参考Technet网站,链接如下:
https://technet.microsoft.com/zh-cn/library/ms189852(v=sql.110).aspx
*****************************************************************************************************
整个SQL Server 2012 数据库镜像的配置分为以下6个小章节
环境准备
安装数据库功能
启用TCP/IP协议和RemoteDAC
数据库准备工作
数据库镜像配置
功能验证
*****************************************************************************************
1. 环境准备
1.1 本次Demo使用的服务器清单如下:
No. |
主机名 |
服务器角色 |
操作系统 |
IP地址 |
1 |
DC01.huangjh.com |
AD/DNS |
Windows Server 2012 R2 |
192.168.8.8/24 |
2 |
SQL01.huangjh.com |
数据库服务器 (主体) |
Windows Server 2012 R2 SQL Server Enterprise 2012 SP1 |
192.168.8.10/24 |
3 |
SQL02.huangjh.com |
数据库服务器 (镜像) |
Windows Server 2012 R2 SQL Server Enterprise 2012 SP1 |
192.168.8.20/24 |
4 |
SQL03.huangjh.com |
数据库服务器 (见证) |
Windows Server 2012 R2 SQL Server Enterprise 2012 SP1 |
192.168.8.30/24 |
1.2 准备好一台域控服务器和三台数据库服务器,配置网络并加入域huangjh.com
1.3 三台SQL服务器需要开放1433和5022端口,为了实验方便本次Demo直接手动关闭防火墙
2. 安装数据库功能
2.1 在SQL01、SQL02和SQL03三台数据库服务器,打开服务器管理器并根据向导完成.Net framework 3.5的安装
2.2在SQL01、SQL02和SQL03三台数据库服务器分别插入并运行SQL Server 2012 Enterprise SP1安装程序,点击“安装”—“全新SQL Server独立安装或向现有安装添加功能”,根据向导完成SQL功能的安装
2.3 在”功能选择”页面,根据实际应用需求勾选所需的功能,下一步
2.4 在”服务器配置”页面,修改服务账户为域账户(确保该账户密码永不过期),启动类型为”自动”
2.5 根据向导在SQL01、SQL02、SQL03完成数据库功能的成功安装
3. 启用TCP/IP协议和RemoteDAC
3.1 在SQL01、SQL02、SQL03中分别打开SQL Server配置管理器,启用TCP/IP协议
3.2 在SQL01、SQL02、SQL03中分别打开SQL Server Management Studio,右键实例选择“方面”
3.3 选择“外围应用配置器”—将属性“RemoteDACEnabled”的值改为“True”
4. 数据库准备工作(创建、备份和还原数据库)
4.1 在SQL01(主体服务器)右键”数据库”—“新建数据库”
4.2 在”常规“页面输入数据库名称
4.3 在”选项”页面确保恢复模式为”完整“
4.4 右键”DB01”选择”任务“—”备份“
4.5 备份类型选择”完整“,点击”确定“
4.6 备份成功完成后点击”确定“
4.7 选择备份类型为”事务日志“,点击”确定“完成对事务日志的备份
4.8 将备份文件拷贝到镜像服务器SQL02.huangjh.com对应的路径,默认备份路径为
“C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup”
4.9 在镜像服务器SQL02.huangjh.com打开SQL Server Management Studio,右键“数据库”选择“创建数据库”
4.10 输入数据库名称,点击“确定”(此数据库名称必须与SQL01中创建的数据库名称保持一致)
4.11 右键新创建的数据库“DB01”--选择“任务”—“还原”—“数据库”
4.12 选择“设备”,点击右边“…”
4.13 点击”添加”
4.14 选择刚才从SQL01复制的备份文件,点击”确定”
4.15 点击“确定”
4.16 勾选要还原的备份集
4.17 在“选项”页面勾选“覆盖现有数据库”,恢复状态选择“RESTORE WITH NORECOVERY”,取消勾选“还原前进行结尾日志备份”,点击“确定”
4.18 点击“确定”
4.19 数据库DB01显示”正在还原…“
5. 数据库镜像配置
5.1 在主体服务器SQL01.huangjh.com右键“DB01”选择“任务”—“镜像”
5.2 点击“配置安全性”
5.3 下一步
5.4 选择“是”,下一步
5.5 勾选“见证服务器实例”,下一步
5.6 下一步
5.7 点击“浏览更多”
5.8 输入镜像服务器名称SQL02,点击”连接”
5.9 选择镜像服务器实例SQL02,下一步
5.10 同样选择见证服务器实例SQL03,下一步
5.11 输入实例服务账户huangjh\administrator,下一步
5.12 点击“完成”
5.13 成功配置后,点击”关闭”
5.14 点击“开始镜像”
5.15 状态为“已同步:数据库已完全同步”,点击“确定”
5.16 在主体服务器SQL01看到的数据库状态为”主体,正在同步”
5.17 在镜像服务器SQL02看到的数据库状态为”正在还原…”
6. 功能验证
6.1 在主体服务器SQL01右键数据库“DB01”选择“任务”—“启动数据库镜像监视器”
6.2 在此页面可看到数据库镜像的同步状态等
6.3在主体服务器SQL01右键数据库“DB01”选择“属性”
6.4 在选择页“镜像”点击“故障转移”
6.5 点击“是”
6.6 此时主体服务器为SQL02,镜像服务器SQL01,说明手动故障转移成功
6.7 将SQL02(此时的主体服务器)关机,此时自动将主体故障转移到SQL01中
6.8 此时又回到了原先的主体服务器SQL01,镜像服务器SQL02,状态为”没有连接:无法连接镜像服务器实例或见证服务器实例”
6.9 将SQL02开机后恢复正常后,状态为”已同步:数据库已完全同步”,说明自动故障转移成功。
~~~以上是整个SQL Server 2012 数据库镜像配置的分享~~~

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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

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