Azure SQL 托管实例入门Getting started with Azure SQL Managed Instance

适用于: Azure SQL 托管实例

Azure SQL 托管实例创建与最新 SQL Server (Enterprise Edition) 数据库引擎几乎完全兼容的数据库,提供一个本机虚拟网络 (VNet) 实现来解决常见的安全问题,并提供现有 SQL Server 客户惯用的业务模型Azure SQL Managed Instance creates a database with near 100% compatibility with the latest SQL Server (Enterprise Edition) database engine, providing a native virtual network (VNet) implementation that addresses common security concerns, and a business model favorable for existing SQL Server customers.

在本文中,你将找到向你介绍如何快速配置和创建 SQL 托管实例以及迁移数据库的内容参考。In this article, you will find references to content that teach you how to quickly configure and create a SQL Managed Instance and migrate your databases.

快速入门概述Quickstart overview

参考以下快速入门可以快速创建 SQL 托管实例、为客户端应用程序配置虚拟机或点到站点 VPN 连接,并使用 .bak 文件将数据库还原到新的 SQL 托管实例。The following quickstarts enable you to quickly create a SQL Managed Instance, configure a virtual machine or point to site VPN connection for client application, and restore a database to your new SQL Managed Instance using a .bak file.

配置环境Configure environment

作为第一步,你需要使用将放置托管实例的网络环境创建第一个 SQL 托管实例,并启用从要执行查询的计算机或虚拟机到 SQL 托管实例的连接。As a first step, you would need to create your first SQL Managed Instance with the network environment where it will be placed, and enable connection from the computer or virtual machine where you are executing queries to SQL Managed Instance. 可以使用下列指南:You can use the following guides:

  • 使用 Azure 门户创建 SQL 托管实例Create a SQL Managed Instance using the Azure portal. 在 Azure 门户中配置所需的参数(用户名/密码、核心数、最大存储量),并自动创建 Azure 网络环境,而无需了解网络详细信息和基础结构要求。In the Azure portal, you configure the necessary parameters (username/password, number of cores, and max storage amount), and automatically create the Azure network environment without the need to know about networking details and infrastructure requirements. 若要使用自己的网络,或者要自定义网络,请参阅为 Azure SQL 托管实例配置现有虚拟网络为 Azure SQL 托管实例创建虚拟网络If you have your own network that you want to use or you want to customize the network, see configure an existing virtual network for Azure SQL Managed Instance or create a virtual network for Azure SQL Managed Instance.

  • SQL 托管实例在其自身的不带公共终结点的 VNet 中创建。A SQL Managed Instance is created in its own VNet with no public endpoint. 若要进行客户端应用程序访问,可“在同一 VNet(不同子网)中创建 VM”,或参考以下快速入门之一“从客户端计算机与 VNet 建立点到站点 VPN 连接” :For client application access, you can either create a VM in the same VNet (different subnet) or create a point-to-site VPN connection to the VNet from your client computer using one of these quickstarts:

    备注

    • 也可以从本地网络使用 Express Route 或站点到站点连接,但这些方法不在这些快速入门的讨论范围内。You can also use express route or site-to-site connection from your local network, but these approaches are out of the scope of these quickstarts.
    • 请注意,如果将保持期从 0(无限制保留)更改为任意其他值,“保留”将仅适用于保留值更改后所写入的日志(仍保留在保留值设置为“无限制”的期间所写入的日志,即使启用了前述保留)。If you change retention period from 0 (unlimited retention) to any other value, please note that retention will only apply to logs written after retention value was changed (logs written during the period when retention was set to unlimited are preserved, even after retention is enabled).

作为手动创建 SQL 托管实例的替代方法,可使用 PowerShell带资源管理器模板的 PowerShellAzure CLI 来编写脚本并自动执行此过程。As an alternative to manual creation of SQL Managed Instance, you can use PowerShell, PowerShell with Resource Manager template, or Azure CLI to script and automate this process.

迁移数据库Migrate your databases

创建 SQL 托管实例并配置访问权限后,可以开始迁移 SQL Server 数据库。After you create a SQL Managed Instance and configure access, you can start migrating your SQL Server databases. 如果要迁移的源数据库中存在一些不受支持的功能,则迁移可能会失败。Migration can fail if you have some unsupported features in the source database that you want to migrate. 若要避免失败并检查兼容性,可以使用数据迁移助手 (DMA) 来对 SQL Server 上的数据库进行分析并找出可能会阻止迁移到 SQL 托管实例的任何问题,例如,是否存在 FileStream 或多个日志文件。To avoid failures and check compatibility, you can use Data Migration Assistant (DMA) to analyze your databases on SQL Server and find any issue that could block migration to a SQL Managed Instance, such as existence of FileStream or multiple log files. 解决这些问题后,即可将数据库迁移到 SQL 托管实例。If you resolve these issues, your databases are ready to migrate to SQL Managed Instance. 数据库实验助手是另一个有用的工具,它可以记录 SQL Server 上的工作负载,并在 SQL 托管实例上重放该工作负载,以便可以确定在迁移到 SQL 托管实例时是否会出现任何性能问题。Database Experimentation Assistant is another useful tool that can record your workload on SQL Server and replay it on a SQL Managed Instance so you can determine are there going to be any performance issues if you migrate to a SQL Managed Instance.

确保可将数据库迁移到 SQL 托管实例后,可以使用本机 SQL Server 还原功能通过 .bak 文件将数据库还原到 SQL 托管实例。Once you are sure that you can migrate your database to a SQL Managed Instance, you can use the native SQL Server restore capabilities to restore a database into a SQL Managed Instance from a .bak file. 可以使用此方法从本地安装的 SQL Server 数据库引擎或 Azure 虚拟机迁移数据库。You can use this method to migrate databases from SQL Server database engine installed on-premises or Azure Virtual Machines. 请参阅快速入门从备份还原到 SQL 托管实例For a quickstart, see Restore from backup to a SQL Managed Instance. 此快速入门介绍了如何使用 RESTORE Transact-SQL 命令从 Azure Blob 存储中存储的 .bak 文件还原。In this quickstart, you restore from a .bak file stored in Azure Blob storage using the RESTORE Transact-SQL command.

提示

若要使用 BACKUP Transact-SQL 命令创建 Azure Blob 存储中数据库的备份,请参阅 SQL Server 备份到 URLTo use the BACKUP Transact-SQL command to create a backup of your database in Azure Blob storage, see SQL Server backup to URL.

参考这些快速入门可以快速创建、配置数据库备份并将其还原到 SQL 托管实例。These quickstarts enable you to quickly create, configure, and restore database backup to a SQL Managed Instance. 在某些情况下,需要自定义或自动化 SQL 托管实例和所需网络环境的部署。In some scenarios, you would need to customize or automate deployment of SQL Managed Instance and the required networking environment. 下面将会介绍这些方案。These scenarios will be described below.

自定义网络环境Customize network environment

尽管在使用 Azure 门户创建实例时可以自动配置 VNet/子网,但最好是在开始创建 SQL 托管实例中的实例之前创建 VNet/子网,因为这样可以配置 VNet 和子网的参数。Although the VNet/subnet can be automatically configured when the instance is created using the Azure portal, it might be good to create it before you start creating instances in SQL Managed Instance because you can configure the parameters of VNet and subnet. 创建和配置网络环境的最简单方法是使用 Azure 资源部署模板,这样可以创建并配置实例所要放入到的网络和子网。The easiest way to create and configure the network environment is to use the Azure Resource deployment template that creates and configures your network and subnet where the instance will be placed. 只需按下 Azure 资源管理器部署按钮,然后在表单中填充参数即可。You just need to press the Azure Resource Manager deploy button and populate the form with parameters.

或者,也可以使用此 PowerShell 脚本自动创建网络。As an alternative, you can also use this PowerShell script to automate creation of the network.

如果已有一个可用于部署 SQL 托管实例的 VNet 和子网,需要确保该 VNet 和子网符合网络要求If you already have a VNet and subnet where you would like to deploy your SQL Managed Instance, you need to make sure that your VNet and subnet satisfy the networking requirements. 使用此 PowerShell 脚本来验证子网的配置是否正确Use this PowerShell script to verify that your subnet is properly configured. 此脚本可以验证网络并报告问题,告知应该更改哪些设置,然后让你在 VNet/子网中进行必要的更改。This script validates your network and reports any issues, telling you what should be changed and then offers to make the necessary changes in your VNet/subnet. 如果你不想要手动配置 VNet/子网,请运行此脚本。Run this script if you don't want to configure your VNet/subnet manually. 对网络基础结构做出任何重大配置更改后,也可以运行此脚本。You can also run it after any major reconfiguration of your network infrastructure. 若要创建并配置自己的网络,请参阅连接体系结构,以及这篇有关创建和配置 SQL 托管实例环境的最终指南If you want to create and configure your own network, read connectivity architecture and this ultimate guide for creating and configuring a SQL Managed Instance environment.

迁移到 SQL 托管实例Migrate to a SQL Managed Instance

上述快速入门使你能够快速设置 SQL 托管实例,以及使用本机 RESTORE 功能移动数据库。The previously-mentioned quickstarts enable you to quickly set up a SQL Managed Instance and move your databases using the native RESTORE capability. 如果想要快速完成概念验证,并验证解决方案在 Azure SQL 数据库托管实例上是否有效,这是一个很好的起点。This is a good starting point if you want to complete quick proof-of concepts and verify that your solution can work on Managed Instance.

但是,若要迁移生产数据库,甚至迁移用于某些性能测试的开发/测试数据库,则需要考虑使用其他技术,例如:However, in order to migrate your production database or even dev/test databases that you want to use for some performance test, you would need to consider using some additional techniques, such as:

  • 性能测试 - 测量源 SQL Server 实例的基线性能指标,并将其与迁移数据库的目标 SQL 托管实例上的性能指标进行比较。Performance testing - You should measure baseline performance metrics on your source SQL Server instance and compare them with the performance metrics on the destination SQL Managed Instance where you have migrated the database. 详细了解性能比较的最佳做法Learn more about the best practices for performance comparison.
  • 联机迁移 - 使用本文所述的本机 RESTORE 时,必须等待数据库还原完毕(如果该数据库尚未存储在 Azure Blob 存储中,还要等待复制到其中)。Online migration - With the native RESTORE described in this article, you have to wait for the databases to be restored (and copied to Azure Blob storage if not already stored there). 这会导致应用程序出现一段停机时间,尤其是数据库较大时。This causes some downtime of your application especially for larger databases. 若要移动生产数据库,请使用数据迁移服务 (DMS),它可以在尽量缩短停机时间的情况下迁移数据库。To move your production database, use the Data Migration service (DMS) to migrate your database with the minimal downtime. 为实现这种迁移,DMS 会以增量方式将源数据库中发生的更改推送到所要还原的 SQL 托管实例数据库。DMS accomplishes this by incrementally pushing the changes made in your source database to the SQL Managed Instance database being restored. 这样,便可以在尽量缩短停机时间的前提下,快速将应用程序从源数据库切换到目标数据库。This way, you can quickly switch your application from source to target database with minimal downtime.

详细了解建议的迁移过程Learn more about the recommended migration process.

后续步骤Next steps