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

Note

将要查看的是 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 create an Azure Database for MySQL server in about five minutes 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 门户Open your web browser, and then go to the Azure portal. 输入登录到门户所需的凭据。Enter your credentials to sign in to the portal. 默认视图是服务仪表板。The default view is your service dashboard.

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

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

按照以下步骤创建 Azure Database for MySQL 服务器:Follow these steps to create an Azure Database for MySQL server:

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

  2. 在搜索框中键入 Azure Database for MySQL 以查找该服务。Type Azure Database for MySQL in the search box to find the service.

    Azure Database for MySQL 选项

  3. 使用以下信息填写“新服务器详细信息”窗体:Fill out the new server details form with the following information:

    “创建服务器”窗体

    设置Setting 建议的值Suggested value 字段说明Field description
    服务器名称Server name 唯一的服务器名称Unique server name 选择用于标识 Azure Database for MySQL 服务器的唯一名称。Choose a unique name that identifies your Azure Database for MySQL server. 例如,mydemoserver。For example, mydemoserver. 域名 .mysql.database.chinacloudapi.cn 追加到所提供的服务器名称后面。The domain name .mysql.database.chinacloudapi.cn is appended to the server name you provide. 服务器名称只能包含小写字母、数字和连字符 (-) 字符。The server name can contain only lowercase letters, numbers, and the hyphen (-) character. 必须包含 3 到 63 个字符。It must contain from 3 to 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 get billed for the resource.
    资源组Resource group myresourcegroupmyresourcegroup 提供新的或现有的资源组名称。Provide a new or existing resource group name.
    选择源Select source 空白Blank 选择“空白”可从头开始创建新服务器。Select Blank to create a new server from scratch. (如果要从现有 Azure Database for MySQL 服务器的异地备份创建服务器,请选择“备份”)。(You select Backup if you are creating a server from a geo-backup of an existing Azure Database for MySQL 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 为服务器管理员帐户提供新密码。Provide a new password for the server admin account. 必须包含 8 到 128 个字符。It must contain from 8 to 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 your other Azure applications.
    版本Version 最新主版本The latest major version 最新主版本(除非你有需要其他版本的特定需求)。The latest major version (unless you have specific requirements that require another version).
    定价层Pricing tier 常规用途第 5 代2 vCore5 GB7 天异地冗余General Purpose, Gen 5, 2 vCores, 5 GB, 7 days, Geographically Redundant 新服务器的计算、存储和备份配置。The compute, storage, and backup configurations for your new server. 选择“定价层”。Select Pricing tier. 接下来,选择“常规用途”选项卡。“第 5 代”、“4 个 vCore”、“100 GB”和“7 天”分别是“计算代系”、“vCore”、“存储”和“备份保持期”的默认值。Next, select the General Purpose tab. Gen 5, 4 vCores, 100 GB, and 7 days are the default values for Compute Generation, vCore, Storage, and Backup Retention Period. 可以将这些滑块保留原样。You can leave those sliders as is. 若要在异地冗余存储中启用服务器备份,请从备份冗余选项中选择“异地冗余”。To enable your server backups in geo-redundant storage, select Geographically Redundant from the Backup Redundancy Options. 若要保存此定价层选择,请选择“确定”。To save this pricing tier selection, select OK. 下一个屏幕截图捕获了这些选择。The next screenshot captures these selections.

    Note

    如果轻量级计算和 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. 在工具栏上选择“通知”(钟形图标)以监视部署过程。Select Notifications on the toolbar (the bell icon) to monitor the deployment process.

    默认情况下,将在服务器下创建以下数据库: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 MySQL 服务在服务器级别创建防火墙。The Azure Database for MySQL service creates a firewall at the server level. 除非创建了防火墙规则来为特定的 IP 地址打开防火墙,否则此防火墙会阻止外部应用程序和工具连接到服务器和服务器上的任何数据库。It prevents external applications and tools from connecting to the server and any databases on the server, unless a firewall rule is created to open the firewall for specific IP addresses.

  1. 部署完成后,找到服务器。After the deployment finishes, locate your server. 可以根据需要进行搜索。If necessary, you can search for it. 例如,从左侧菜单选择“所有资源”。For example, select All Resources from the menu on the left. 然后键入服务器名称(例如 mydemoserver),以搜索新创建的服务器。Then type in the server name, such as the example mydemoserver, to search for your newly created server. 从搜索结果列表中选择服务器名称。Select the server name from the search result list. 服务器的“概述”页面随即打开,其中提供了用于进一步配置的选项。The Overview page for your server opens and provides options for further configuration.

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

  3. 在“防火墙规则”标题下,选择“规则名称”列中的空白文本框,开始创建防火墙规则。Under the Firewall rules heading, select the blank text box in the Rule Name column to begin creating the firewall rule. 输入将访问此服务器的客户端的准确 IP 范围。Enter the precise range of IPs of the clients that will be accessing this server.

    连接安全性 - 防火墙规则

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

    Note

    连接到 Azure Database for MySQL 时,经端口 3306 进行通信。Connections to Azure Database for MySQL communicate over port 3306. 如果尝试从企业网络内部进行连接,则可能不允许经端口 3306 的出站流量。If you try to connect from within a corporate network, outbound traffic over port 3306 might not be allowed. 如果是这样,则无法连接到服务器,除非 IT 部门打开了端口 3306。If this is the case, you can't connect to your server unless your IT department opens port 3306.

获取连接信息Get the 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 the Quickstart article. 如果没有记下这些值,可以在 Azure 门户的服务器“概览”页或“属性”页中轻松地找到服务器名称和登录信息。If you didn't, you can easily find the server name and sign-in information from the server Overview page or the Properties page in the Azure portal.

若要查找这些值,请执行以下步骤:To find these values, take the following steps:

  1. 打开服务器的“概览”页。Open your server's Overview page. 记下“服务器名称”和“服务器管理员登录名”。Make a note of the Server name and Server admin login name.

  2. 将光标悬停在每个字段,然后复制图标就会显示在文本右侧。Hover your cursor over each field, and the copy icon appears to the right of the text. 根据需要选择复制图标即可复制这些值。Select the copy icon as needed to copy the values.

在此示例中,服务器名称是 mydemoserver.mysql.database.chinacloudapi.cn,服务器管理员登录名是 myadmin@mydemoserverIn this example, the server name is mydemoserver.mysql.database.chinacloudapi.cn, and the server admin sign-in is myadmin@mydemoserver.

使用 mysql 命令行工具连接到 MySQLConnect to MySQL by using the mysql command-line tool

使用 mysql.exe 命令行工具连接到服务器。Connect to your server using the mysql.exe command-line tool. 可从此处下载 MySQL 并将其安装在计算机上。You can download MySQL from here and install it on your computer.

  1. 若要借助 mysql 实用程序连接到 Azure Database for MySQL 服务器,请使用以下格式:To connect to an Azure Database for MySQL server with 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.mysql.database.chinacloudapi.cn --user myadmin@mydemoserver -p
    
    mysql 参数mysql parameter 建议的值Suggested value 说明Description
    --host--host 服务器名称Server name 此前在创建 Azure Database for MySQL 服务器时使用过的服务器名称值。The server name value that you used earlier when you created the Azure Database for MySQL server. 示例服务器为 mydemoserver.mysql.database.chinacloudapi.cnOur example server is mydemoserver.mysql.database.chinacloudapi.cn. 请使用完全限定域名 (*.mysql.database.chinacloudapi.cn),如示例中所示。Use the fully qualified domain name (*.mysql.database.chinacloudapi.cn) as shown in the example. 如果不记得服务器名称,请按上一部分的步骤操作,以便获取连接信息。If you don't remember your server name, follow the steps in the previous section to get the connection information.
    --user--user 服务器管理员登录名Server admin login name 此前在创建 Azure Database for MySQL 服务器时提供的服务器管理员登录用户名。The server admin login username that you supplied when you created the Azure Database for MySQL server earlier. 如果不记得用户名,请按上一部分的步骤操作,以便获取连接信息。If you don't remember the username, follow the steps in the previous section to get the connection information. 格式为“username@servername”。The format is username@servername.
    -p-p 等待系统提示Wait until prompted 如果系统提示,请提供在创建服务器时提供的密码。When prompted, provide the same password that you provided when you created the server. 注意,键入密码字符时,这些字符不会显示在 bash 提示符处。Note that the typed password characters are not shown on the bash prompt when you type them. 输入密码后,选择 Enter。After you've entered the password, select Enter.

    连接后,mysql 实用程序会显示 mysql> 提示符,提示你键入命令。After it's connected, the mysql utility displays a mysql> prompt at which you can type commands.

    下面是 mysql 输出示例:Following is example mysql output:

    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 65505
    Server version: 5.6.26.0 MySQL Community Server (GPL)
    
    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
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    

    Tip

    如果未将防火墙配置为允许客户端的 IP 地址,则会出现以下错误:If the firewall is not configured to allow the IP address of your client, the following error occurs:

    错误 2003 (28000): 不允许 IP 地址为 123.456.789.0 的客户端访问服务器。ERROR 2003 (28000): Client with IP address 123.456.789.0 is not allowed to access the server.

    若要解决此错误,请确保服务器配置符合本文“配置服务器级防火墙规则”部分相关步骤的要求。To resolve the error, make sure the server configuration matches the steps in the "Configure a server-level firewall rule" section of the article.

  2. 若要确保连接正常,请在 mysql> 提示符处键入 status,以便查看服务器状态。To ensure the connection is functional, view the server status by typing status at the mysql> prompt.

    status
    

    Tip

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

  3. 在 mysql> 提示符处键入以下命令,创建空数据库:Create a blank database at the mysql> prompt by typing the following command:

    CREATE DATABASE quickstartdb;
    

    该命令可能需要一定的时间才能完成。The command might take a few moments to complete.

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

  4. 通过在 mysql > 提示符处键入以下命令来列出数据库:List the databases at the mysql> prompt by typing the following command:

    SHOW DATABASES;
    
  5. 键入 \q,然后选择 Enter 键,退出 mysql 工具。Type \q, and then select the Enter key to quit the mysql tool.

现在,你已连接到 Azure Database for MySQL 服务器并创建空白用户数据库。Now you have connected to the Azure Database for MySQL server and created a blank user database. 请转到下一部分进行类似的练习。Continue to the next section for a similar exercise. 下一练习使用另一常用工具(即 MySQL Workbench)连接到同一服务器。The next exercise connects to the same server by using another common tool, MySQL Workbench.

使用 MySQL Workbench GUI 工具连接到服务器Connect to the server by using the MySQL Workbench GUI tool

若要使用 GUI 工具 MySQL Workbench 连接到服务器,请执行以下步骤:To connect to the server by using the GUI tool MySQL Workbench, take the following steps:

  1. 打开客户端计算机上的 MySQL Workbench 应用程序。Open the MySQL Workbench application on your client computer. 可以从 Download MySQL Workbench(下载 MySQL Workbench)下载并安装 MySQL Workbench。You can download and install MySQL Workbench from Download MySQL Workbench.

  2. 创建新连接。Create a new connection. 单击“MySQL 连接”标题旁边的加号 (+) 图标。Click the plus (+) icon beside the MySQL Connections heading.

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

    设置新连接

    设置Setting 建议的值Suggested value 字段说明Field description
    连接名称Connection name 演示连接Demo connection 此连接的标签。A label for this connection.
    连接方法Connection method 标准 (TCP/IP)Standard (TCP/IP) 标准 (TCP/IP) 就足够了。Standard (TCP/IP) is sufficient.
    主机名Hostname 服务器名称Server name 此前在创建 Azure Database for MySQL 服务器时使用过的服务器名称值。The server name value that you used when you created the Azure Database for MySQL server earlier. 示例服务器为 mydemoserver.mysql.database.chinacloudapi.cnOur example server is mydemoserver.mysql.database.chinacloudapi.cn. 请使用完全限定域名 (*.mysql.database.chinacloudapi.cn),如示例中所示。Use the fully qualified domain name (*.mysql.database.chinacloudapi.cn) as shown in the example. 如果不记得服务器名称,请按上一部分的步骤操作,以便获取连接信息。If you don't remember your server name, follow the steps in the previous section to get the connection information.
    端口Port 33063306 连接到 Azure Database for MySQL 服务器时需要使用的端口。The port to use when connecting to your Azure Database for MySQL server.
    用户名Username 服务器管理员登录名Server admin login name 此前在创建 Azure Database for MySQL 服务器时提供的服务器管理员登录信息。The server admin sign-in information that you supplied when you created the Azure Database for MySQL server earlier. 示例用户名是 myadmin@mydemoserverOur example username is myadmin@mydemoserver. 如果不记得用户名,请按上一部分的步骤操作,以便获取连接信息。If you don't remember the username, follow the steps in the previous section to get the connection information. 格式为 username@servername。The format is username@servername.
    密码Password 你的密码Your password 选择“在保管库中存储...”按钮来保存密码。Select the Store in Vault... button to save the password.
  4. 选择“测试连接”以测试是否所有参数均已正确配置。Select Test Connection to test whether all parameters are configured correctly. 然后选择“确定”以保存连接。Then select OK to save the connection.

    Note

    默认情况下,SSL 是在服务器上强制实施的,需要额外配置才能成功进行连接。SSL is enforced by default on your server and requires extra configuration to connect successfully. 有关详细信息,请参阅配置应用程序中的 SSL 连接性以安全连接到 Azure Database for MySQLFor more information, see Configure SSL connectivity in your application to securely connect to Azure Database for MySQL. 就本快速入门来说,若要禁用 SSL,请转到 Azure 门户。To disable SSL for this Quickstart, go to the Azure portal. 然后选择“连接安全性”页,禁用“强制实施 SSL”连接切换按钮。Then select the Connection security page to disable the Enforce SSL connection toggle button.

清理资源Clean up resources

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

Tip

本教程系列中的其他快速入门教程是在本文的基础上制作的。Other Quickstarts in this collection build on this Quickstart. 如果打算继续使用快速入门,请不要清除在本快速入门中创建的资源。If you plan to continue working with 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 with this Quickstart.

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

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

  2. 在资源组页上,选择“删除”。On your resource group page, select Delete. 然后在框中键入确认删除的资源组的名称(例如 myresourcegroup 示例),再选择“删除”。Then type the name of your resource group (such as our example myresourcegroup) in the box to confirm deletion, and select Delete.

若只删除新创建的服务器,请执行以下步骤:To delete only the newly created server, take the following steps:

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

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

    Azure Database for MySQL--删除服务器

  3. 确认要删除的服务器的名称,并显示其下受影响的数据库。Confirm the name of the server that you want to delete, and show the databases under it that are affected. 在框中键入服务器名称(例如 mydemoserver)。Type your server name in the box (such as our example mydemoserver). 选择“删除” 。Select Delete.

后续步骤Next steps