快速入門:使用 Azure 入口網站建立 Azure Database for MySQL 伺服器Quickstart: Create an Azure Database for MySQL server by using the Azure portal

適用於 MySQL 的 Azure 資料庫是一個受控服務,您可用來在雲端執行、管理及調整高可用性 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 入口網站建立適用於 MySQL 的 Azure 資料庫單一伺服器。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.

PrerequisitesPrerequisites

需要有效的 Azure 訂用帳戶。An Azure subscription is required. 如果您沒有 Azure 訂用帳戶,請在開始前建立免費 Azure 帳戶If you don't have an Azure subscription, create a free Azure account before you begin.

建立適用於 MySQL 的 Azure 資料庫單一伺服器Create an Azure Database for MySQL single server

  1. 移至 Azure 入口網站,建立 MySQL 單一伺服器資料庫。Go to the Azure portal to create a MySQL Single Server database. 搜尋並選取 [適用於 MySQL 的 Azure 資料庫]:Search for and select Azure Database for MySQL:

    尋找適用於 MySQL 的 Azure 資料庫

  2. 選取 [新增] 。Select Add.

  3. 在 [選取適用於 MySQL 的 Azure 資料庫部署選項] 頁面上,選取 [單一伺服器]: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 NoneNone 選取 [無] 從頭建立新的伺服器。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 個虛擬核心 以及 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_superuseradminadministratorrootguestpublic 作為管理使用者名稱。You can't use azure_superuser, admin, administrator, root, guest, or public for the admin user name.
    密碼Password 密碼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:

    顯示「您的部署已完成」訊息的螢幕擷取畫面。

有問題嗎?請告訴我們。Having problems? Let us know.

設定伺服器層級防火牆規則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 的輸出流量,以供適用於 MySQL 的 Azure 資料庫使用。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. 如需詳細資訊,請參閱如何在適用於 MySQL 的 Azure 資料庫上管理防火牆規則For more information, see How to manage firewall rules on an Azure Database for MySQL server.

有問題嗎?請告訴我們Having problems? Let us know

使用 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. 在本快速入門中,我們將在 Azure Cloud Shell 中執行 mysql.exe,以連線至伺服器。In this quickstart, we'll use mysql.exe in Azure Cloud Shell to connect to the server.

  1. 選取工具列上的第一個按鈕,在入口網站中開啟 Azure Cloud Shell,如下列螢幕擷取畫面所示。Open Azure Cloud Shell in the portal by selecting the first button on the toolbar, as shown in the following screenshot. 請在 [概觀] 區段中記下新伺服器的伺服器名稱、伺服器管理員名稱和訂用帳戶,如螢幕擷取畫面所示。Note the server name, server admin name, and subscription for your new server in the Overview section, as shown in the screenshot.

    注意

    如果您是第一次開啟 Cloud Shell,系統將會提示您建立資源群組和儲存體帳戶。If you're opening Cloud Shell for the first time, you'll be prompted to create a resource group and storage account. 此步驟只需執行一次。This is a one-time step. 系統會為所有工作階段連結此項目。It will be automatically attached for all sessions.

    在 Azure 入口網站中顯示 Cloud Shell 的螢幕擷取畫面。

  2. 在 Azure Cloud Shell 終端機內執行下列命令。Run the following command in the Azure Cloud Shell terminal. 請將此處顯示的值取代為您的實際伺服器名稱和管理使用者名稱。Replace the values shown here with your actual server name and admin user name. 對於適用於 MySQL 的 Azure 資料庫,您必須將 @\<servername> 新增至管理使用者名稱,如下所示:For Azure Database for MySQL, you need to add @\<servername> to the admin user name, as shown here:

    mysql --host=mydemoserver.mysql.database.azure.com --user=myadmin@mydemoserver -p
    

    以下是在 Cloud Shell 終端機中呈現的樣貌:Here's what it looks like in the Cloud Shell terminal:

    Requesting a Cloud Shell.Succeeded.
    Connecting terminal...
    
    Welcome to Azure Cloud Shell
    
    Type "az" to use Azure CLI
    Type "help" to learn about Cloud Shell
    
    user@Azure:~$mysql -h mydemoserver.mysql.database.azure.com -u myadmin@mydemoserver -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 64796
    Server version: 5.6.42.0 Source distribution
    
    Copyright (c) 2000, 2020, 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>
    
  3. 在相同的 Azure Cloud Shell 終端機中,建立名為 guest 的資料庫:In the same Azure Cloud Shell terminal, create a database named guest:

    mysql> CREATE DATABASE guest;
    Query OK, 1 row affected (0.27 sec)
    
  4. 切換至 guest 資料庫:Switch to the guest database:

    mysql> USE guest;
    Database changed
    
  5. 輸入 quit,然後選取 Enter 以結束 mysql。Enter quit, and then select Enter to quit mysql.

有問題嗎?請告訴我們。Having problems? Let us know.

清除資源Clean up resources

您此時已在資源群組中建立適用於 MySQL 的 Azure 資料庫伺服器。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

找不到您要尋找的內容嗎?請告訴我們。Can't find what you're looking for? Let us know.