使用 Azure 门户创建 Azure Database for MariaDB 服务器Create an Azure Database for MariaDB server by using the Azure portal

Azure Database for MariaDB 是一种托管服务,可用于在云中运行、管理和缩放高可用性的 MariaDB 数据库。Azure Database for MariaDB is a managed service you can use to run, manage, and scale highly available MariaDB databases in the cloud. 本快速入门介绍了如何使用 Azure 门户在大约五分钟内创建 Azure Database for MariaDB 服务器。This quickstart shows you how to create an Azure Database for MariaDB server in about five minutes by using the Azure portal.

如果没有 Azure 订阅,请在开始前创建一个试用 Azure 帐户If you don't have an Azure subscription, create a trial Azure account before you begin.

登录到 Azure 门户Sign in to the Azure portal

在 Web 浏览器中转到 Azure 门户In your web browser, go to the Azure portal. 输入登录到门户所需的凭据。Enter your credentials to sign in to the portal. 默认视图是服务仪表板。The default view is your service dashboard.

创建 Azure Database for MariaDB 服务器Create an Azure Database for MariaDB server

创建 Azure Database for MariaDB 服务器时,请使用定义好的一组计算和存储资源You create an Azure Database for MariaDB server with a defined set of compute and storage resources. 请在 Azure 资源组中创建该服务器。You create the server within an Azure resource group.

若要创建 Azure Database for MariaDB 服务器,请执行以下操作:To create an Azure Database for MariaDB server:

  1. 选择门户左上角的“创建资源”按钮 (+) 。Select the Create a resource button (+) in the upper left corner of the portal.

  2. 选择“数据库” > “Azure Database for MariaDB” 。Select Databases > Azure Database for MariaDB. 还可以在搜索框中键入“MariaDB”以查找该服务 。You can also type MariaDB in the search box to find the service.

    Azure Database for MariaDB 选项

  3. 输入或选择以下服务器详细信息:Enter or select the following server details:


    设置Setting 建议的值Suggested value 说明Description
    服务器名称Server name 唯一的服务器名称a unique server name 选择用于标识 Azure Database for MariaDB 服务器的唯一名称。Choose a unique name that identifies your Azure Database for MariaDB server. 例如,mydemoserverFor example, mydemoserver. 域名 .mariadb.database.chinacloudapi.cn 将追加到你输入的服务器名称后面。The domain name .mariadb.database.chinacloudapi.cn is appended to the server name you enter. 服务器名称只能包含小写字母、数字和连字符 (-) 字符。The server name can contain only lowercase letters, numbers, and the hyphen (-) character. 它必须包含 3 到 63 个字符。It must contain between 3 and 63 characters.
    订阅Subscription 订阅your subscription 选择要用于服务器的 Azure 订阅。Select the Azure subscription that you want to use for your server. 如果有多个订阅,请选择要计费的资源所在的订阅。If you have multiple subscriptions, choose the subscription in which you are billed for the resource.
    资源组Resource group myresourcegroupmyresourcegroup 输入新的资源组名称,或选择现有的资源组。Enter a new resource group name or select an existing resource group.
    选择源Select source 空白Blank 选择“空白” 可从头开始创建新服务器。Select Blank to create a new server from scratch. (如果要从现有 Azure Database for MariaDB 服务器的异地备份创建服务器,请选择“备份” 。)(Select Backup if you are creating a server from a geo-backup of an existing Azure Database for MariaDB server.)
    服务器管理员登录名Server admin login myadminmyadmin 连接到服务器时需使用的登录帐户。A sign-in account to use when you're connecting to the server. 管理员登录名不能是“azure_superuser”、“admin”、“administrator”、“root”、“guest”或“public”。 The admin sign-in name cannot be azure_superuser, admin, administrator, root, guest, or public.
    密码Password 由用户选择your choice 为服务器管理员帐户输入新密码。Enter a new password for the server admin account. 该密码必须包含 8 到 128 个字符。It must contain between 8 and 128 characters. 密码必须包含以下三个类别的字符:英文大写字母、英文小写字母、数字 (0-9)和非字母数字字符(!, $, #, % 等)。Your password must contain characters from three of the following categories: English uppercase letters, English lowercase letters, numbers (0-9), and non-alphanumeric characters (!, $, #, %, and so on).
    确认密码Confirm password 由用户选择your choice 确认管理员帐户密码。Confirm the admin account password.
    位置Location 离用户最近的区域the region closest to your users 选择最靠近用户或其他 Azure 应用程序的位置。Choose the location that is closest to your users or to your other Azure applications.
    版本Version 最新版本the latest version 最新版本,有特定要求(即要求使用其他版本)的除外。The latest version (unless you have specific requirements to use a different version).
    定价层Pricing tier 请参阅说明。See description. 新服务器的计算、存储和备份配置。The compute, storage, and backup configurations for your new server. 选择“定价层” > “常规用途”。Select Pricing tier > General Purpose. 为以下设置保留默认值:Keep the default values for the following settings:
    • 计算代系(第 5 代)Compute Generation (Gen 5)
    • vCore(4 个 vCore)vCore (4 vCores)
    • 存储空间 (100 GB)Storage (100 GB)
    • 备份保持期(7 天)Backup Retention Period (7 days)

    若要在异地冗余存储中启用服务器备份,请选择“异地冗余”作为“备份冗余选项” 。To enable your server backups in geo-redundant storage, for Backup Redundancy Options, select Geographically Redundant.

    若要保存此定价层选择,请选择“确定” 。To save this pricing tier selection, select OK. 下一个屏幕截图捕获了这些选择。The next screenshot captures these selections.


    如果轻量级计算和 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 cannot later be scaled to General Purpose or Memory Optimized. 有关详细信息,请参阅定价页See the pricing page for more information.

    “创建服务器 - 定价层”窗口

  4. 选择“创建” 以预配服务器。Select Create to provision the server. 预配可能需要长达 20 分钟的时间。Provisioning can take up to 20 minutes.

  5. 若要监视部署过程,请在工具栏上选择“通知”(钟形图标)。 To monitor the deployment process, select Notifications on the toolbar (the bell icon).

默认情况下,将在服务器下创建以下数据库:information_schemamysqlperformance_schemasysBy default, the following databases are created under your server: information_schema, mysql, performance_schema, and sys.

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

Azure Database for MariaDB 服务在服务器级别创建防火墙。The Azure Database for MariaDB service creates a firewall at the server level. 除非创建了防火墙规则来为特定的 IP 地址打开防火墙,否则防火墙会阻止外部应用程序和工具连接到服务器或服务器上的任何数据库。The firewall prevents external applications and tools from connecting to the server or to any databases on the server unless a firewall rule is created to open the firewall for specific IP addresses.

若要创建服务器级防火墙规则,请执行以下操作:To create a server-level firewall rule:

  1. 部署完成后,请找到服务器。When deployment is finished, locate your server. 可以根据需要进行搜索。If necessary, you can search for it. 例如,在左侧菜单中,选择“所有资源” 。For example, in the left menu, select All Resources. 然后,输入服务器名称。Then, enter the server name. 例如,输入 mydemoserver,以便搜索新建的服务器。For example, enter mydemoserver to search for your newly created server. 从搜索结果列表中选择服务器名称。Select the server name from the search result list. 此时会打开服务器的“概览”页。 The Overview page for your server opens. 可以在此页上更改其他设置。You can change additional settings on this page.

  2. 在服务器概览页中,选择“连接安全性” 。On the server overview page, select Connection security.

  3. 在“防火墙规则”下,选择“规则名称”列中的空白文本框,开始创建防火墙规则。 Under Firewall rules, select the blank text box in the Rule Name column to begin creating the firewall rule. 指定将连接到此服务器的客户端的精确 IP 范围。Specify the precise IP range of the clients that will connect to this server.

    连接安全性 - 防火墙规则

  4. 在“连接安全性”页的上部工具栏中,选择“保存”。 On the upper toolbar of the Connection security page, select Save. 在继续操作之前,请等待指示更新已成功完成的通知出现。Before you continue, wait until you see the notification that says the update has finished successfully.


    连接到 Azure Database for MariaDB 时,经端口 3306 进行通信。Connections to Azure Database for MariaDB communicate over port 3306. 如果尝试从企业网络内部进行连接,则可能不允许经端口 3306 的出站流量。If you try to connect from inside a corporate network, outbound traffic over port 3306 might not be allowed. 这种情况下,若要连接到服务器,必须要求 IT 部门打开端口 3306。In this case, to connect to your server, your IT department must open port 3306.

获取连接信息Get connection information

若要连接到数据库服务器,需提供完整的服务器名称和管理员登录凭据。To connect to your database server, you need the full server name and admin sign-in credentials. 此前可能已在本文中记下这些值。You might have noted those values earlier in this article. 如果没有记下这些值,可以在 Azure 门户的服务器“概览”页或“属性”页中轻松地找到服务器名称和登录信息: If you didn't, you can easily find the server name and sign-in information on the server Overview page or on the Properties page in the Azure portal:

  1. 转到服务器的“概览” 页。Go to your server's Overview page. 记下“服务器名称” 和“服务器管理员登录名” 的值。Make a note of the values for Server name and Server admin login name.

  2. 若要复制这些值,请将光标放置在要复制的字段上方。To copy the values, place your cursor over the field you want to copy. 复制图标会显示在文本右侧。The copy icon appears to the right of the text. 根据需要选择复制图标即可复制这些值。Select the copy icon as needed to copy the values.

在我们的示例中,服务器名称是 mydemoserver.mariadb.database.chinacloudapi.cn,服务器管理员登录名是 myadmin@mydemoserverIn our example, the server name is mydemoserver.mariadb.database.chinacloudapi.cn and the server admin login name is myadmin@mydemoserver.

使用 mysql 命令行连接到 Azure Database for MariaDBConnect to Azure Database for MariaDB by using the mysql command line

可以通过多个应用程序连接到 Azure Database for MariaDB 服务器。You can use a variety of applications to connect to your Azure Database for MariaDB server.

  1. 首先,我们将使用 mysql 命令行工具来演示如何连接到该服务器。First, we'll use the mysql command-line tool to illustrate how to connect to the server.

在 Powershell 提示符下输入以下 mysql 命令行,连接到 Azure Database for MariaDB 服务器。At the Powershell prompt, connect to your Azure Database for MariaDB server by entering the mysql command line.

若要通过 mysql 实用程序连接到 Azure Database for MariaDB 服务器,请使用以下格式:To connect to an Azure Database for MariaDB server by using the mysql utility, use the following format:

mysql --host <fully qualified server name> --user <server admin login name>@<server name> -p

例如,以下命令连接到示例服务器:For example, the following command connects to our example server:

mysql --host mydemoserver.mariadb.database.chinacloudapi.cn --user myadmin@mydemoserver -p

<span data-ttu-id="d974c-217">mysql 参数</span><span class="sxs-lookup"><span data-stu-id="d974c-217">mysql parameter</span></span> |<span data-ttu-id="d974c-218">建议的值</span><span class="sxs-lookup"><span data-stu-id="d974c-218">Suggested value</span></span>|<span data-ttu-id="d974c-219">说明</span><span class="sxs-lookup"><span data-stu-id="d974c-219">Description</span></span>
<span data-ttu-id="d974c-220">--host</span><span class="sxs-lookup"><span data-stu-id="d974c-220">--host</span></span> | <span data-ttu-id="d974c-221">服务器名称 </span><span class="sxs-lookup"><span data-stu-id="d974c-221">*server name*</span></span> | <span data-ttu-id="d974c-222">在创建 Azure Database for MariaDB 服务器时使用的服务器名称值。</span><span class="sxs-lookup"><span data-stu-id="d974c-222">The server name value that you used to create the Azure Database for MariaDB server.</span></span> <span data-ttu-id="d974c-223">示例服务器为 **mydemoserver.mariadb.database.chinacloudapi.cn**。</span><span class="sxs-lookup"><span data-stu-id="d974c-223">Our example server is **mydemoserver.mariadb.database.chinacloudapi.cn**.</span></span> <span data-ttu-id="d974c-224">请使用完全限定域名 ( **\*.mariadb.database.chinacloudapi.cn**),如示例中所示。</span><span class="sxs-lookup"><span data-stu-id="d974c-224">Use the fully qualified domain name (**\*.mariadb.database.chinacloudapi.cn**) as shown in the example.</span></span> <span data-ttu-id="d974c-225">如果不记得服务器名称,请完成上一部分的步骤,以便获取连接信息。</span><span class="sxs-lookup"><span data-stu-id="d974c-225">If you don't remember your server name, complete the steps in the preceding section to get the connection information.</span></span>
<span data-ttu-id="d974c-226">--user</span><span class="sxs-lookup"><span data-stu-id="d974c-226">--user</span></span> | <span data-ttu-id="d974c-227">服务器管理员登录名 </span><span class="sxs-lookup"><span data-stu-id="d974c-227">*server admin login name*</span></span> |<span data-ttu-id="d974c-228">在创建 Azure Database for MariaDB 服务器时使用的服务器管理员登录用户名。</span><span class="sxs-lookup"><span data-stu-id="d974c-228">The server admin login user name that you used to create the Azure Database for MariaDB server.</span></span> <span data-ttu-id="d974c-229">如果不记得用户名,请完成上一部分的步骤,以便获取连接信息。</span><span class="sxs-lookup"><span data-stu-id="d974c-229">If you don't remember the user name, complete the steps in the preceding section to get the connection information.</span></span> <span data-ttu-id="d974c-230">格式为 username\@servername  。</span><span class="sxs-lookup"><span data-stu-id="d974c-230">The format is *username\@servername*.</span></span>
<span data-ttu-id="d974c-231">-p</span><span class="sxs-lookup"><span data-stu-id="d974c-231">-p</span></span> | <span data-ttu-id="d974c-232">你的密码 </span><span class="sxs-lookup"><span data-stu-id="d974c-232">*your password*</span></span><br><span data-ttu-id="d974c-233">(等待系统提示)</span><span class="sxs-lookup"><span data-stu-id="d974c-233">(wait until prompted)</span></span> |<span data-ttu-id="d974c-234">出现提示时,输入用于创建服务器的密码。</span><span class="sxs-lookup"><span data-stu-id="d974c-234">When prompted, enter the password that you used to create the server.</span></span> <span data-ttu-id="d974c-235">键入密码字符时,这些字符不会显示在 bash 提示符处。</span><span class="sxs-lookup"><span data-stu-id="d974c-235">The typed password characters are not shown on the bash prompt when you type them.</span></span> <span data-ttu-id="d974c-236">输入密码后,按 Enter。</span><span class="sxs-lookup"><span data-stu-id="d974c-236">After you enter the password, press Enter.</span></span>

连接 mysql 实用程序后,它会显示 mysql> 提示符。When the mysql utility is connected, it displays a mysql> prompt. 可以在提示符下输入命令。You can enter commands at the prompt.

下面是 mysql 输出的示例:Here's an example of mysql output:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 65505
Server version: MariaDB Server

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.



如果未将防火墙配置为允许 Azure Cloud Shell 的 IP 地址,则会出现以下错误:If the firewall isn't configured to allow the IP address of Azure Cloud Shell, the following error occurs:

ERROR 2003 (28000): Client with IP address 123.456.789.0 is not allowed to access the server.ERROR 2003 (28000): Client with IP address 123.456.789.0 is not allowed to access the server.

若要解决此错误,请确保服务器配置符合配置服务器级防火墙规则中所述步骤的要求。To resolve the error, ensure that the server configuration matches the steps that are described in Configure a server-level firewall rule.

  1. 若要验证连接,请在 mysql> 提示符处输入 status,以便检查服务器状态。To verify the connection, enter status at the mysql> prompt to check the server status.



    有关其他命令,请参阅 MySQL 5.7 参考手册 - 第 4.5.1 章For additional commands, see MySQL 5.7 Reference Manual - Chapter 4.5.1.

  2. 在出现 mysql> 提示时通过输入以下命令,以便创建空数据库:Create a blank database at the mysql> prompt by entering the following command:

    CREATE DATABASE quickstartdb;

    该命令可能需要几分钟时间才能完成。The command might take a few minutes to finish.

    可以在 Azure Database for MariaDB 服务器中创建一个或多个数据库。You can create one or more databases on an Azure Database for MariaDB server. 可以为每个服务器创建单一数据库来使用所有资源,也可以创建多个数据库来共享资源。You can create a single database per server to utilize all resources, or you can create multiple databases to share the resources. 可以创建的数据库数目没有限制,但多个数据库共享相同的服务器资源。There's no limit on the number of databases that you can create, but multiple databases share the same server resources.

  3. 若要列出数据库,请在 mysql> 提示符处输入以下命令:To list the databases, at the mysql> prompt, enter the following command:

  4. 输入 \q,然后按 Enter 关闭 mysql 工具。Enter \q, and then press Enter to close the mysql tool. 然后可以关闭 PowerShell。Then, you can close PowerShell.

你已连接到 Azure Database for MariaDB 服务器并创建一个空白用户数据库。You have connected to the Azure Database for MariaDB server and created a blank user database. 在下一部分,请使用另一常用工具(即 MySQL Workbench)连接到同一服务器。In the next section, you connect to the same server by using another common tool, MySQL Workbench.

使用 MySQL Workbench 连接服务器Connect to the server by using MySQL Workbench

若要使用 MySQL Workbench 连接到服务器,请执行以下操作:To connect to the server by using MySQL Workbench:

  1. 打开客户端计算机上的 MySQL Workbench。Open MySQL Workbench on your client computer. 若要下载并安装 MySQL Workbench,请访问 下载 MySQL WorkbenchTo download and install MySQL Workbench, go to Download MySQL Workbench.

  2. 若要创建新的连接,请选择“MySQL 连接”标题旁边的加号 ( + )。 To create a new connection, select the plus icon (+) next to the MySQL Connections heading.

  3. 在“设置新连接” 对话框的“参数” 选项卡上,输入服务器连接信息。In the Setup New Connection dialog box, on the Parameters tab, enter your server connection information. 占位符值作为示例显示。Placeholder values are shown as an example. 请将“主机名”、“用户名”和“密码”替换为自己的值。 Replace Hostname, Username, and Password with your own values.


    设置Setting 建议的值Suggested value 字段说明Field description
    连接名称Connection name Demo connectionDemo connection 此连接的标签。A label for this connection.
    连接方法Connection method Standard (TCP/IP)Standard (TCP/IP) 标准 (TCP/IP) 就足够了。Standard (TCP/IP) is sufficient.
    主机名Hostname 服务器名称 server name 在创建 Azure Database for MariaDB 服务器时使用的服务器名称值。The server name value that you used to create the Azure Database for MariaDB server. 示例服务器为 mydemoserver.mariadb.database.chinacloudapi.cnOur example server is mydemoserver.mariadb.database.chinacloudapi.cn. 请使用完全限定域名 ( *.mariadb.database.chinacloudapi.cn),如示例中所示。Use the fully qualified domain name (*.mariadb.database.chinacloudapi.cn) as shown in the example. 如果不记得服务器名称,请完成本文前面的步骤,以便获取连接信息。If you don't remember your server name, complete the steps earlier in this article to get the connection information.
    端口Port 33063306 连接到 Azure Database for MariaDB 服务器时要使用的端口。The port to use when you connect to your Azure Database for MariaDB server.
    用户名Username 服务器管理员登录名 server admin login name 在创建 Azure Database for MariaDB 服务器时使用的服务器管理员登录信息。The server admin sign-in information that you used to create the Azure Database for MariaDB server. 示例用户名是 myadmin@mydemoserver 。Our example user name is myadmin@mydemoserver. 如果不记得用户名,请完成本文前面的步骤,以便获取连接信息。If you don't remember the user name, complete the steps earlier in this article to get the connection information. 格式为 username@servername 。The format is username@servername.
    密码Password 你的密码 your password 若要保存密码,请选择“在保管库中存储” 。To save the password, select Store in Vault.
  4. 若要检查所有参数是否已正确配置,请选择“测试连接” 。To check that all parameters are configured correctly, select Test Connection. 然后,选择“确定” 以保存连接。Then, select OK to save the connection.


    默认情况下,SSL 是在服务器上强制实施的,SSL is enforced by default on your server. 需要额外配置才能成功进行连接。It requires additional configuration to connect successfully. 有关详细信息,请参阅配置应用程序中的 SSL 连接性以安全连接到 Azure Database for MariaDBFor more information, see Configure SSL connectivity in your application to securely connect to Azure Database for MariaDB. 若要禁用本快速入门的 SSL,请在 Azure 门户的服务器概览页的菜单中选择“连接安全性”。 To disable SSL for this quickstart, on the server overview page in the Azure portal, select Connection security in the menu. 对于“强制实施 SSL 连接”,请选择“禁用”。 For Enforce SSL connection, select Disabled.

清理资源Clean up resources

可以通过两种方式清理在本快速入门中创建的资源。You can clean up the resources that you created in this quickstart in two ways. 可以删除 Azure 资源组You can delete the Azure resource group. 此选项删除资源组中的所有资源。This option deletes all the resources in the resource group. 若要保持其他资源原封不动,请只删除单服务器资源。If you want to keep the other resources intact, delete only the one server resource.


本教程系列中的其他快速入门教程是在本文的基础上制作的。Other quickstarts in this collection build on this quickstart. 如果打算继续使用 Azure Database for MariaDB 快速入门,请不要清除在本快速入门中创建的资源。If you plan to continue working with Azure Database for MariaDB quickstarts, don't clean up the resources that you created in this quickstart. 如果不打算继续,请执行以下步骤,删除在本快速入门中创建的所有资源。If you don't plan to continue, use the following steps to delete all the resources that you created in this quickstart.

若要删除包括新建服务器在内的整个资源组,请执行以下操作:To delete the entire resource group, including the newly created server:

  1. 在 Azure 门户中查找资源组。In the Azure portal, locate your resource group. 在左侧菜单中选择“资源组” ,然后选择资源组的名称(在我们的示例中为 myresourcegroup)。 In the left menu, select Resource groups, and then select the name of your resource group (in our example, myresourcegroup).

  2. 在资源组页上,选择“删除” 。On the resource group page, select Delete. 然后,键入确认删除的资源组的名称(在我们的示例中为 myresourcegroup)。Then, enter the name of your resource group (in our example, myresourcegroup) to confirm deletion. 选择“删除” 。Select Delete.

仅删除新建的服务器:To delete only the newly created server:

  1. 在 Azure 门户中找到服务器(如果尚未将其打开)。In the Azure portal, locate your server if you don't already have it open. 在左侧菜单中,选择“所有资源” 。In the left menu, select All resources. 然后搜索所创建的服务器。Then, search for the server you created.

  2. 在“概览” 页上,选择“删除” 。On the Overview page, select Delete.

    Azure Database for MariaDB - 删除服务器

  3. 确认要删除的服务器的名称。Confirm the name of the server you want to delete. 在它下面显示会受删除影响的数据库。Show the databases under it that will be affected by the deletion. 输入确认删除的服务器名称(在我们的示例中为 mydemoserver)。Enter your server name (in our example, mydemoserver) to confirm deletion. 选择“删除” 。Select Delete.

后续步骤Next steps