快速入门:使用 Azure 门户创建 Azure Database for MySQL 服务器Quickstart: Create an Azure Database for MySQL server by using the Azure portal

备注

将要查看的是 Azure Database for MySQL 的新服务。You are viewing the new service of Azure Database for MySQL. 若要查看经典 MySQL Database for Azure 的文档,请访问此页To view the documentation for classic MySQL Database for Azure, please visit this page.

Azure Database for MySQL 是一种托管服务,可用于在云中运行、管理和缩放具有高可用性的 MySQL 数据库。Azure Database for MySQL is a managed service that you use to run, manage, and scale highly available MySQL databases in the cloud. 本快速入门介绍如何使用 Azure 门户创建 Azure Database for MySQL 单一服务器,This quickstart shows you how to use the Azure portal to create an Azure Database for MySQL single server. 以及如何连接到该服务器。It also shows you how to connect to the server.

先决条件Prerequisites

需要一个 Azure 订阅。An Azure subscription is required. 如果没有 Azure 订阅,可在开始前创建一个 Azure 试用帐户If you don't have an Azure subscription, create an Azure trial account before you begin.

创建 Azure Database for MySQL 单一服务器Create an Azure Database for MySQL single server

  1. 转到 Azure 门户创建 MySQL 单一服务器数据库。Go to the Azure portal to create a MySQL Single Server database. 搜索并选择“Azure Database for MySQL”:Search for and select Azure Database for MySQL:

    查找 Azure Database for MySQL

  2. 选择 添加Select Add.

  3. 在”选择 Azure Database for MySQL 部署选项”页上,选择“单一服务器”:On the Select Azure Database for MySQL deployment option page, select Single server:

    显示“单一服务器”选项的屏幕截图。

  4. 输入新的单一服务器的基本设置:Enter the basic settings for a new single server:

    显示“创建 MySQL 服务器”页的屏幕截图。

    设置Setting 建议的值Suggested value 说明Description
    订阅Subscription 你的订阅Your subscription 选择所需的 Azure 订阅。Select the desired Azure subscription.
    资源组Resource group myresourcegroupmyresourcegroup 输入新资源组,或订阅中的现有资源组。Enter a new resource group or an existing one from your subscription.
    服务器名称Server name mydemoservermydemoserver 输入唯一名称。Enter a unique name. 服务器名称只能包含小写字母、数字和连字符 (-) 字符。The server name can contain only lowercase letters, numbers, and the hyphen (-) character. 必须包含 3 到 63 个字符。It must contain 3 to 63 characters.
    数据源Data source None 选择“无”,从头开始创建新的服务器 。Select None to create a new server from scratch. 仅当从现有服务器的异地备份进行还原时,才选择“备份”。Select Backup only if you're restoring from a geo-backup of an existing server.
    位置Location 你所需的位置Your desired location 从列表中选择一个位置。Select a location from the list.
    版本Version 最新主版本The latest major version 使用最新主版本。Use the latest major version. 请参阅所有受支持的版本See all supported versions.
    计算 + 存储Compute + storage 使用默认值Use the defaults 默认定价层是“常规用途”,其中包含 4 个 vCore 和 100 GB 存储 。The default pricing tier is General Purpose with 4 vCores and 100 GB storage. 备份保留期设置为 7 天,并提供“异地冗余”备份选项 。Backup retention is set to 7 days, with the Geographically Redundant backup option.
    查看定价页,根据需要更新默认值。Review the pricing page, and update the defaults if you need to.
    管理员用户名Admin username mydemoadminmydemoadmin 输入服务器管理员用户名。Enter your server admin user name. 不能将“azure_superuser”、“admin”、“administrator”、“root”、“guest”或“public”用作管理员用户名 。You can't use azure_superuser, admin, administrator, root, guest, or public for the admin user name.
    PasswordPassword 密码A password 服务器管理员用户的新密码。A new password for the server admin user. 密码长度必须为 8 到 128 个字符,并包含大写字母或小写字母、数字和非字母数字字符(!、$、#、% 等)的组合。The password must be 8 to 128 characters long and contain a combination of uppercase or lowercase letters, numbers, and non-alphanumeric characters (!, $, #, %, and so on).

    备注

    如果轻量级计算和 I/O 足以满足工作负荷要求,请考虑使用“基本”定价层。Consider using the Basic pricing tier if light compute and I/O are adequate for your workload. 请注意,在“基本”定价层中创建的服务器以后不能扩展到“常规用途”或“内存优化”定价层。Note that servers created in the Basic pricing tier can't later be scaled to General Purpose or Memory Optimized.

  5. 选择“查看 + 创建” 以预配服务器。Select Review + create to provision the server.

  6. 等待门户页显示“你的部署已完成”消息。Wait for the portal page to display Your deployment is complete. 选择“转到资源”,转到新建服务器页:Select Go to resource to go to the newly created server page:

    显示“部署已完成”消息的屏幕截图。

配置服务器级防火墙规则Configure a server-level firewall rule

默认情况下,新服务器受防火墙保护。By default, the new server is protected with a firewall. 若要进行连接,必须通过完成以下步骤提供对 IP 的访问权限:To connect, you must provide access to your IP by completing these steps:

  1. 转到服务器资源左侧窗格中的“连接安全性”。Go to Connection security from the left pane for your server resource. 如果不知道如何找到资源,请参阅如何打开资源If you don't know how to find your resource, see How to open a resource.

    显示“连接安全性”>“防火墙规则”页的屏幕截图。

  2. 选择“添加当前客户端 IP 地址”,然后选择“保存” 。Select Add current client IP address, and then select Save.

    备注

    若要避免连接问题,请检查网络是否允许通过端口 3306 送出出站流量,该端口由 Azure Database for MySQL 使用。To avoid connectivity problems, check if your network allows outbound traffic over port 3306, which is used by Azure Database for MySQL.

可以添加更多 IP 或提供一个 IP 范围,以便从这些 IP 连接到服务器。You can add more IPs or provide an IP range to connect to your server from those IPs. 有关详细信息,请参阅如何在 Azure Database for MySQL 服务器上管理防火墙规则For more information, see How to manage firewall rules on an Azure Database for MySQL server.

通过 mysql.exe 连接到服务器Connect to the server by using mysql.exe

可以使用 mysql.exeMySQL Workbench 从本地环境连接到服务器。You can use either mysql.exe or MySQL Workbench to connect to the server from your local environment. 在本快速入门中,我们将使用 shell 中的 mysql.exe 连接到服务器。In this quickstart, we'll use mysql.exe in the shell to connect to the server.

  1. 将此处所示的值替换为实际的服务器名称和管理员用户名。Replace the values shown here with your actual server name and admin user name. 对于 Azure Database for MySQL,需要为管理员用户名添加 @\<servername>,如下所示:For Azure Database for MySQL, you need to add @\<servername> to the admin user name, as shown here:

    mysql --host=mydemoserver.mysql.database.chinacloudapi.cn --user=myadmin@mydemoserver -p
    
  2. 创建名为 guest 的数据库:Create a database named guest:

    mysql> CREATE DATABASE guest;
    Query OK, 1 row affected (0.27 sec)
    
  3. 切换到 guest 数据库:Switch to the guest database:

    mysql> USE guest;
    Database changed
    
  4. 输入 quit,然后选择 Enter 退出 mysql。Enter quit, and then select Enter to quit mysql.

清理资源Clean up resources

现在已在资源组中创建 Azure Database for MySQL 服务器。You have now created an Azure Database for MySQL server in a resource group. 如果将来不再需要这些资源,可以通过删除资源组来删除它们,也可以直接删除 MySQL 服务器。If you don't expect to need these resources in the future, you can delete them by deleting the resource group, or you can just delete the MySQL server. 若要删除资源组,请完成以下步骤:To delete the resource group, complete these steps:

  1. 在 Azure 门户中,搜索并选择“资源组”。In the Azure portal, search for and select Resource groups.
  2. 在资源组列表中,选择资源组的名称。In the list of resource groups, select the name of your resource group.
  3. 在资源组的“概述”页中,选择“删除资源组” 。On the Overview page for your resource group, select Delete resource group.
  4. 在确认对话框中,键入资源组的名称,然后选择“删除”。In the confirmation dialog box, type the name of your resource group, and then select Delete.

若要删除服务器,可以在服务器的“概述”页中选择“删除”,如下所示 :To delete the server, you can select Delete on the Overview page for your server, as shown here:

显示服务器概述页中的“删除”按钮的屏幕截图。

后续步骤Next steps