快速入門:在 Azure 入口網站中建立適用於 MySQL 的 Azure 資料庫伺服器Quickstart: Create an Azure Database for MySQL server in 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 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 free 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.

建立適用於 MySQL 的 Azure 資料庫伺服器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 Create a resource (+) in the upper-left corner of the portal.

  2. 選取 [資料庫] > [Azure Database for MySQL] 。Select Databases > Azure Database for MySQL. 您也可以在搜尋方塊中輸入 MySQL 以尋找此服務。You can also enter MySQL in the search box to find the service.

適用於 MySQL 的 Azure 資料庫 選項Azure Database for MySQL option

  1. 在新伺服器詳細資料表單中填寫下列資訊︰Fill out the new server details form with the following information:

建立伺服器表單Create server form

設定Setting 建議的值Suggested value 欄位描述Field description
訂用帳戶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. 您可以使用資源群組來組織屬於單一專案的相依性。Resource group can be used organize your dependencies that belong to single project.
伺服器名稱Server name 唯一的伺服器名稱Unique server name 輸入可識別 Azure Database for MySQL 伺服器的唯一名稱。Enter a unique name that identifies your Azure Database for MySQL server. 例如 'mysqldbserver'。伺服器名稱只能包含小寫字母、數字及連字號 (-) 字元。For example, 'mysqldbserver'.The server name can contain only lowercase letters, numbers, and the hyphen (-) character. 此名稱必須包含 3 到 63 個字元。It must contain from 3 to 63 characters.
資料來源Data source NoneNone 選取 [無] 從頭建立新的伺服器。Select None to create a new server from scratch. (如果您要從現有「適用於 MySQL 的 Azure 資料庫」伺服器的異地備份建立伺服器,可以選取 [備份])。(You would select Backup if you were creating a server from a geo-backup of an existing Azure Database for MySQL server).
伺服器管理員登入Server admin login myadminmyadmin 輸入伺服器管理員的使用者名稱。Enter a username for your server administrator. 您不能使用 azure_superuseradminadministratorrootguestpublic 作為管理使用者名稱。You cannot use azure_superuser, admin, administrator, root, guest, or public as the admin username.
密碼Password 您的選擇Your choice 為伺服器管理帳戶提供新密碼。Provide a new password for the server admin account. 密碼的長度必須為 8 到 128 個字元,且包含大寫或小寫字母、數字和非英數字元 (!、$、#、% 等等) 的組合。Password must be 8 to 128 characters in length with a combination of uppercase or lowercase letters, numbers, and non-alphanumeric characters (!, $, #, %, and so on).
確認密碼Confirm password 您的選擇Your choice 確認管理帳戶密碼。Confirm the admin account password.
LocationLocation 最接近使用者的區域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).
計算 + 儲存體Compute + Storage 一般用途Gen 52 個虛擬核心5 GB7 天異地備援General Purpose, Gen 5, 2 vCores, 5 GB, 7 days, Geographically Redundant 新伺服器的計算、儲存體和備份組態。The compute, storage, and backup configurations for your new server. 選取 [設定伺服器] 。Select Configure server. 接下來,選取適當的定價層;如需詳細資訊,請參閱定價頁面Next, select the appropriate pricing tier, for more information, see the pricing page. 若要啟用異地備援儲存體中的伺服器備份,請從 [備份備援選項] 中選取 [異地備援]。To enable your server backups in geo-redundant storage, select Geographically Redundant from the Backup Redundancy Options. 選取 [確定]。Select OK.

注意

如果您的工作負載只需要輕量計算和 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.

  1. 選取 [檢閱+建立] 以佈建伺服器。Select Review + create to provision the server. 佈建作業可能需要多達 20 分鐘的時間。Provisioning can take up to 20 minutes.

  2. 在工具列上選取 [通知] (鈴鐺圖示) 以監視部署程序。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

根據預設,建立的伺服器受防火牆保護,且不可公開存取。By default the server created is protected with a firewall and is not accessible publicly. 若要授與 IP 存取權,請移至 Azure 入口網站中的伺服器資源,然後從伺服器資源的左側功能表選取 [連線安全性]。To give access to your IP, go to your server resource in the Azure portal and select Connection security from left-side menu for your server resource. 如果不知道如何尋找資源,請參閱如何開啟資源Don't know how to find your resource, see How to open a resource.

連線安全性 - 防火牆規則Connection security - Firewall rules

現在,選取 [新增目前的用戶端 IP 位址],然後選取 [儲存]。Now select Add current client IP address and then select Save. 您可以新增其他 IP 或提供 IP 範圍,以從這些 IP 連線到您的伺服器。You can add additional 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 Azure Database for MySQL server

注意

檢查您的網路是否允許連接埠 3306 的輸出流量,以供適用於 MySQL 的 Azure 資料庫使用以避免連線問題。Check if your network allows outbound traffic over port 3306 that is used by Azure Database for MySQL to avoid connectivity issues.

使用 MySQL 命令列用戶端連線到適用於 MySQL 的 Azure 資料庫伺服器Connect to Azure Database for MySQL server using mysql command-line client

您可以從本機環境中選擇 mysql.exeMySQL Workbench 來連線到伺服器。You can choose either mysql.exe or MySQL Workbench to connect to the server from your local environment. 在本快速入門中,我們將在 Azure Cloud Shell 中執行 mysql.exe 以連線到伺服器。In this quickstart, we will run mysql.exe in Azure Cloud Shell to connect to the server.

  1. 選取左上方反白顯示的圖示,在入口網站中啟動 Azure Cloud Shell。Launch Azure Cloud Shell in the portal by clicking the highlighted icon on the top-left side. 請記下概觀區段中新建立之伺服器的伺服器名稱、伺服器管理員登入名稱、密碼以及訂用帳戶,如下圖所示。Make a note of your server name, server admin login name, password, and subscription for your newly created server from the Overview section as shown in the image below.

    注意

    如果您是第一次啟動 Cloud Shell,會看到建立資源群組、儲存體帳戶的提示。If you are launching cloud shell for the first time, you will see a prompt to create a resource group, storage account. 這是一次性的步驟,而且會針對所有工作階段自動連接。This is a one- time step and will be automatically attached for all sessions.

    入口網站完整檢視 Cloud ShellPortal Full View Cloud Shell

  2. 在 Azure Cloud Shell 終端機上執行此命令。Run this command on Azure Cloud Shell terminal. 將值取代為實際的伺服器名稱和管理員使用者登入名稱。Replace values with your actual server name and admin user login name. 適用於 MySQL 的 Azure 資料庫管理員使用者名稱需要 '@,如下所示The admin username requires '@ as shown below for Azure Database for MySQL

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

以下是 Cloud Shell 終端機中體驗顯示的樣子Here is how the experience 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

sunitha@Azure:~$mysql -h mydemoserver.mysql.database.azure.com -u admin@wpapp-mysqldbserver -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>
  1. 在相同的 Azure Cloud Shell 終端機中,建立資料庫客體In the same Azure Cloud Shell terminal, create a database guest
mysql> CREATE DATABASE guest;
Query OK, 1 row affected (0.27 sec)
  1. 變更為資料庫來賓Change to database guest
mysql> USE guest;
Database changed 
  1. 輸入 quit,然後選取 Enter 鍵結束 mysql。Type quit, and then select the Enter key to quit mysql.

清除資源Clean up resources

您已成功在資源群組中建立適用於 MySQL 的 Azure 資料庫伺服器。You have successfully 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 just delete the MySQL server. 若要移除資源群組,請依照這些步驟操作:To delete the resource group, follow these steps:

  1. 在 Azure 入口網站中,搜尋並選取 [資源群組]。In the Azure portal, search for and select Resource groups.
  2. 在 [資源群組] 清單中,選擇資源群組的名稱。In the resource group list, choose the name of your resource group.
  3. 在資源群組的 [概觀]頁面中,選取 [刪除資源群組]。In the Overview page of 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 click on Delete button on Overview page of your server as shown below:

刪除資源Delete your resources

後續步驟Next steps