您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

将 MariaDB 数据库迁移到 AzureMigrate MariaDB databases to Azure

本文说明了虚构公司 Contoso 如何计划并将其本地 MariaDB 开源数据库平台迁移到 Azure。This article demonstrates how the fictional company Contoso planned and migrated its on-premises MariaDB open-source database platform to Azure.

Contoso 使用的是 MariaDB 而不是 MySQL,原因如下:Contoso is using MariaDB instead of MySQL because of its:

  • 许多存储引擎选项。Numerous storage engine options.
  • 缓存和索引性能。Cache and index performance.
  • 具有功能和扩展的开源支持。Open-source support with features and extensions.
  • 用于分析工作负荷的列存储引擎。ColumnStore storage engine for analytical workloads.

公司的迁移目标是继续使用 MariaDB,但不必担心如何管理支持它所需的环境。The company's migration goal is to continue to use MariaDB but not worry about managing the environment needed to support it.

业务驱动因素Business drivers

IT 领先团队与业务合作伙伴密切合作,以了解他们希望在此迁移中实现的目标。The IT leadership team has worked closely with business partners to understand what they want to achieve with this migration. 它们需要:They want to:

  • 提高可用性。Increase availability. Contoso 在其 MariaDB 本地环境中存在可用性问题。Contoso has had availability issues with its MariaDB on-premises environment. 业务要求使用此数据存储的应用程序更可靠。The business requires the applications that use this data store to be more reliable.
  • 提高效率。Increase efficiency. Contoso 需要删除不必要的过程,并简化开发人员和用户的过程。Contoso needs to remove unnecessary procedures and streamline processes for developers and users. 业务需要快速而不是浪费时间或金钱,以更快地提供客户需求。The business needs IT to be fast and not waste time or money to deliver faster on customer requirements.
  • 提高灵活性。Increase agility. Contoso IT 需要对业务需求更加敏感。Contoso IT needs to be more responsive to the needs of the business. 它必须比 marketplace 中的更改更快地在全球经济中实现成功。It must react faster than the changes in the marketplace to enable success in a global economy. 它不得或成为业务阻止手段。It mustn't get in the way or become a business blocker.
  • 纵向.Scale. 当业务成功发展时,Contoso IT 必须提供以相同步调增长的系统。As the business grows successfully, Contoso IT must provide systems that grow at the same pace.

迁移目标Migration goals

Contoso 云团队制定了本次迁移的目标。The Contoso cloud team has pinned down goals for this migration. 这些目标用于确定最佳迁移方式。These goals were used to determine the best migration method.

要求Requirements 详细信息Details
可用性Availability 目前,内部人员在 MariaDB 实例的宿主环境中遇到了困难。Currently internal staff are having a hard time with the hosting environment for the MariaDB instance. Contoso 希望数据库层的可用性接近99.99%。Contoso wants to have close to 99.99 percent availability for the database layer.
伸缩性Scalability 本地数据库主机的容量快。The on-premises database host is quickly running out of capacity. Contoso 需要一种方法来扩展其实例的当前限制,或在业务环境改变为节省成本的情况下向下缩放。Contoso needs a way to scale its instances past current limitations or scale down if the business environment changes to save on costs.
“性能”Performance Contoso 人力资源 (HR) 部门具有多个报告,每日、每周和每月运行一次。The Contoso human resources (HR) department has several reports it runs on a daily, weekly, and monthly basis. 当它运行这些报表时,它会与面向员工的应用程序发现相当大的性能问题。When it runs these reports, it notices considerable performance issues with the employee-facing application. 它需要在不影响应用程序性能的情况下运行报表。It needs to run the reports without affecting application performance.
安全性Security Contoso 需要知道,只能对其内部应用程序访问数据库,而不能通过 internet 进行查看或访问。Contoso needs to know that the database is accessible only to its internal applications and isn't visible or accessible via the internet.
MonitoringMonitoring Contoso 目前使用工具来监视 MariaDB 数据库的指标,并在 CPU、内存或存储出现问题时提供通知。Contoso currently uses tools to monitor the metrics of the MariaDB database and provide notifications when CPU, memory, or storage have issues. 该公司希望在 Azure 中使用这一功能。The company wants to have this same capability in Azure.
业务连续性Business continuity HR 数据存储是 Contoso 日常操作的重要组成部分。The HR data store is an important part of Contoso's daily operations. 如果它已损坏或需要还原,则该公司希望最大限度地减少停机时间。If it became corrupted or needed to be restored, the company wants to minimize downtime.
AzureAzure Contoso 想要将应用程序移动到 Azure,而不在 Vm 上运行它。Contoso wants to move the application to Azure without running it on VMs. Contoso 要求状态使用 Azure 平台即服务 (PaaS) 用于数据层的服务。Contoso requirements state to use Azure platform as a service (PaaS) services for the data tier.

解决方案设计Solution design

固定目标和需求后,Contoso 设计和审查部署解决方案并识别迁移过程。After pinning down goals and requirements, Contoso designs and reviews a deployment solution and identifies the migration process. 还会标识用于迁移的工具和服务。The tools and services that it will use for migration are also identified.

当前应用程序Current application

MariaDB 数据库托管用于公司 HR 部门的所有方面的员工数据。The MariaDB database hosts employee data that's used for all aspects of the company's HR department. 基于灯泡的应用程序用作处理员工 HR 请求的前端。A LAMP-based application is used as the front end to handle employee HR requests. Contoso 在世界各地有100000的员工,因此运行时间对于其数据库很重要。Contoso has 100,000 employees worldwide, so uptime is important for its databases.

建议的解决方案Proposed solution

  • 评估用于迁移兼容性的环境。Evaluate the environments for migration compatibility.
  • 使用常用的开源工具将数据库迁移到 Azure Database for MariaDB 的实例。Use common open-source tools to migrate databases to the Azure Database for MariaDB instance.
  • 将所有应用程序和进程修改为使用新的 Azure Database for MariaDB 实例。Modify all applications and processes to use the new Azure Database for MariaDB instance.

数据库注意事项Database considerations

作为解决方案设计过程的一部分,Contoso 在 Azure 中查看了用于托管其 MariaDB 数据库的功能。As part of the solution design process, Contoso reviewed the features in Azure for hosting its MariaDB databases. 以下注意事项有助于公司决定使用 Azure:The following considerations helped the company decide to use Azure:

  • 类似于 Azure SQL 数据库,Azure Database for MariaDB 允许 防火墙规则Similar to Azure SQL Database, Azure Database for MariaDB allows for firewall rules.
  • Azure Database for MariaDB 可用于 Azure 虚拟网络 ,以防止实例被公开访问。Azure Database for MariaDB can be used with Azure Virtual Network to prevent the instance from being publicly accessible.
  • Azure Database for MariaDB 具有 Contoso 必须为其审计员满足的符合性和隐私证书要求。Azure Database for MariaDB has the required compliance and privacy certifications that Contoso must meet for its auditors.
  • 将使用读取副本增强报表和应用程序的处理性能。Report and application processing performance will be enhanced by using read replicas.
  • 仅通过使用 Azure Private Link) (非公共访问权限来向内部网络流量公开服务的能力。Ability to expose the service to internal network traffic only (no-public access) by using Azure Private Link.
  • Contoso 选择不迁移到 Azure Database for MySQL,因为将来可能会使用 MariaDB 列存储和图形数据库模型。Contoso chose not to move to Azure Database for MySQL because it's looking at potentially using the MariaDB ColumnStore and graph database model in the future.
  • 从应用程序到数据库的 带宽和延迟 足以根据所选网关 (Azure ExpressRoute 或站点到站点 VPN) 。The bandwidth and latency from the application to the database will be sufficient enough based on the chosen gateway (either Azure ExpressRoute or Site-to-Site VPN).

解决方案评审Solution review

Contoso 通过将利弊清单放置在一起来评估其建议的设计。Contoso evaluates the proposed design by putting together a pros and cons list.

注意事项Consideration 详细信息Details
优点Pros Azure Database for MariaDB 提供99.99% 的财务支持服务级别协议 (SLA) 实现 高可用性Azure Database for MariaDB offers a 99.99 percent financially backed service-level agreement (SLA) for high availability.

在每个季度的高峰负载期间,Azure 提供扩展或缩减功能。Azure offers the ability to scale up or down during peak load times each quarter. Contoso 可以通过购买 预留容量来更好地保存。Contoso can save even more by purchasing reserved capacity.

Azure 为 Azure Database for MariaDB 提供了时间点还原和异地还原功能。Azure provides point-in-time restore and geo-restore capabilities for Azure Database for MariaDB.

缺点Cons Contoso 仅限 Azure 支持的 MariaDB 发行版本,这些版本目前为10.2 和10.3。Contoso is limited to the MariaDB release versions that are supported in Azure, which are currently 10.2 and 10.3.

Azure Database for MariaDB 存在一些 限制,例如缩小存储。Azure Database for MariaDB has some limitations, such as scaling down storage.

建议的体系结构Proposed architecture

关系图显示了方案体系结构。 图1:方案体系结构。Diagram shows the scenario architecture. Figure 1: Scenario architecture.

迁移过程Migration process


在迁移 MariaDB 数据库之前,需要确保这些实例满足成功迁移的所有 Azure 先决条件。Before you can migrate your MariaDB databases, you need to ensure that those instances meet all the Azure prerequisites for a successful migration.

支持的版本:Supported versions:

  • MariaDB 使用 x.x.x.x 命名方案。MariaDB uses the x.y.z naming scheme. 例如,x 是主版本,y 是次版本,z 是修补程序版本。For example, x is the major version, y is the minor version, and z is the patch version.
  • Azure 目前支持10.2.25 和10.3.16。Azure currently supports 10.2.25 and 10.3.16.
  • Azure 会自动管理修补程序更新的升级。Azure automatically manages upgrades for patch updates. 例如,10.2.21 到10.2.23。Examples are 10.2.21 to 10.2.23. 不支持次要和主要版本升级。Minor and major version upgrades aren't supported. 例如,不支持从 MariaDB 10.2 升级到 MariaDB 10.3。For example, upgrading from MariaDB 10.2 to MariaDB 10.3 isn't supported. 如果要从10.2 升级到10.3,请获取数据库转储,并将其还原到使用目标引擎版本创建的服务器。If you want to upgrade from 10.2 to 10.3, take a database dump and restore it to a server created with the target engine version.

网络:The network:

Contoso 需要设置一个从其本地环境到其 MariaDB 数据库所在的虚拟网络的虚拟网络网关连接。Contoso needs to set up a virtual network gateway connection from its on-premises environment to the virtual network where its MariaDB database is located. 此连接允许本地应用程序在连接字符串更新时通过网关访问数据库。This connection allows the on-premises application to access the database over the gateway when the connection strings are updated.

关系图显示了迁移过程。Diagram shows the migration process. 图2:迁移过程。Figure 2: The migration process.


由于 MariaDB 类似于 MySQL,因此 Contoso 可以使用相同的常见实用工具和工具(如 MySQL 工作台、mysqldump、Toad 或 Navicat)连接到 Azure Database for MariaDB 并将其迁移到。Because MariaDB is similar to MySQL, Contoso can use the same common utilities and tools such as MySQL Workbench, mysqldump, Toad, or Navicat to connect to and migrate data to Azure Database for MariaDB.

Contoso 使用以下步骤迁移了其数据库。Contoso used the following steps to migrate its databases.

  • 通过运行以下命令并观察输出来确定本地 MariaDB 版本。Determine the on-premises MariaDB version by running the following commands and observing the output. 在大多数情况下,你的版本对架构和数据转储不应太重要。In most cases, your version shouldn't matter much for the schema and data dump. 如果要在应用程序级别使用功能,请确保这些应用程序与 Azure 中的目标版本兼容。If you're using features at the application level, ensure those applications are compatible with the target version in Azure.

      mysql -h localhost -u root -P

    屏幕截图显示如何确定本地 MariaDB 版本。 图3:确定本地 MariaDB 版本。Screenshot shows how to determine the on-premises MariaDB version. Figure 3: Determining the on-premises MariaDB version.

  • 在 Azure 中创建新的 MariaDB 实例:Create a new MariaDB instance in Azure:

    • 打开 Azure 门户Open the Azure portal.

    • 选择 " 添加资源"。Select Add a resource.

    • 搜索 MariaDBSearch for MariaDB.

      屏幕截图显示 Azure 中的新 MariaDB 实例。 图4: Azure 中的新 MariaDB 实例。Screenshot shows a new MariaDB instance in Azure. Figure 4: A new MariaDB instance in Azure.

    • 选择“创建” 。Select Create.

    • 选择订阅和资源组。Select your subscription and resource group.

    • 选择服务器名称和位置。Select a server name and location.

    • 选择目标版本,即10.2 或10.3。Select your target version, which is 10.2 or 10.3.

    • 选择计算和存储。Select your compute and storage.

    • 输入管理员用户名和密码。Enter an admin username and password.

    • 选择“查看 + 创建”。Select Review + create.

      * * Create MariaDB Server * * 页的屏幕截图。 图5:查看和创建。Screenshot of the Create MariaDB Server page. Figure 5: Review and create.

    • 选择“创建” 。Select Create.

    • 记录服务器主机名、用户名和密码。Record the server hostname, username, and password.

    • 选择 " 连接安全性"。Select Connection Security.

    • 选择 " 添加客户端 IP (要从) 还原数据库的 IP。Select Add Client IP (the IP that you'll be restoring the database from).

    • 选择“保存”。Select Save.

  • 运行以下命令以导出名为的数据库 EmployeesRun the following commands to export the database called Employees. 为每个数据库重复:Repeat for each database:

    mysqldump -h localhost -u root -p --skip-triggers --single-transaction --extended-insert --order-by-primary --disable-keys Employees > Employees.sql
  • 还原数据库。Restore the database. 将替换为 Azure Database for MariaDB 实例的终结点,并将替换为用户名:Replace with the endpoint for your Azure Database for MariaDB instance and the username:

    mysql -h {name}.mariadb.database.azure.com -u user@{name} -p -ssl
    create database employees;
    use database employees;
    source employees.sql;
  • 使用 phpMyAdmin 或类似的工具(如 MySQL 工作台、Toad 和 Navicat)通过检查每个表中的记录计数来验证还原。Use phpMyAdmin or a similar tool, such as MySQL Workbench, Toad, and Navicat, to verify the restore by checking record counts in each table.

  • 将所有应用程序连接字符串更新为指向迁移的数据库。Update all application connection strings to point to the migrated database.

  • 测试所有应用程序是否正常运行。Test all applications for proper operation.

迁移后的清理Clean up after migration

成功迁移后,Contoso 需要备份并存储本地数据库备份文件,以便进行保留。After a verified successful migration, Contoso needs to back up and store the on-premises database backup files for retention purposes. 停用本地 MariaDB 服务器。Retire the on-premises MariaDB server.

查看部署Review the deployment

Azure 中存在已迁移的资源后,Contoso 需要全面运营并保护其新基础设施。With the migrated resources in Azure, Contoso needs to fully operationalize and secure its new infrastructure.


Contoso 需要:Contoso needs to:

  • 请确保其新的 Azure Database for MariaDB 实例和数据库是安全的。Ensure that its new Azure Database for MariaDB instance and databases are secure. 有关详细信息,请参阅 Azure Database for MariaDB 中的安全性For more information, see Security in Azure Database for MariaDB.
  • 查看 防火墙规则 和虚拟网络配置,验证连接是否仅限需要它的应用程序。Review the firewall rules and virtual network configurations to verify that connections are limited to only the applications that require it.
  • 将任何出站 IP 要求配置为允许连接到 MariaDB 网关 IP 地址Configure any outbound IP requirements to allow connections to the MariaDB gateway IP addresses.
  • 更新所有应用程序以要求对数据库进行 SSL 连接。Update all applications to require SSL connections to the databases.
  • 设置 专用链接 ,以便将所有数据库流量保存在 Azure 和本地网络中。Set up Private Link so that all database traffic is kept inside Azure and the on-premises network.
  • 为标识启用 Microsoft DefenderEnable Microsoft Defender for Identity.
  • 配置 Log Analytics 以监视和发送相关警报的警报和日志项。Configure Log Analytics to monitor and send alerts on security and logs entries of interest.


确保使用异地还原备份 Azure Database for MariaDB 的实例。Ensure that the Azure Database for MariaDB instances are backed up by using geo-restore. 这样一来,如果发生区域中断,备份可以在配对的区域中使用。In this way, backups can be used in a paired region if a regional outage occurs.


请确保 Azure Database for MariaDB 实例具有 资源锁 ,以防止删除该实例。Make sure that the Azure Database for MariaDB instance has a resource lock to prevent it from being deleted. 无法还原已删除的服务器。Deleted servers can't be restored.

许可和成本优化Licensing and cost optimization

  • Azure Database for MariaDB 可以向上或向下缩放。Azure Database for MariaDB can be scaled up or down. 服务器和数据库的性能监视非常重要,可确保您满足您的需求,同时还需保持成本最低。Performance monitoring of the server and databases is important to ensure you meet your needs but also keep costs at a minimum.
  • CPU 和存储都有相关的成本。Both CPU and storage have costs associated. 可以选择多个定价层。There are several pricing tiers to select from. 请确保为数据工作负荷选择适当的定价计划。Be sure the appropriate pricing plan is selected for the data workloads.
  • 每个读取副本根据所选的计算和存储计费。Each read replica is billed based on the compute and storage selected.
  • 使用保留容量节省成本。Use reserved capacity to save on costs.


在本文中,Contoso 将其 MariaDB 数据库迁移到 Azure Database for MariaDB 的实例。In this article, Contoso migrated its MariaDB databases to an Azure Database for MariaDB instance.