Create an Azure Database for MySQL server via the Azure portal

In this tutorial series, you will learn how to create an Azure Database for MySQL and connect to the database by using Python. Then you will use Python and SQL statements to insert, read, select, order, update, and delete data in the database.

In the first part of this tutorial series, you will learn how to create an Azure Database for MySQL single server via the Azure Portal, create a new database and configure firewall rules to enable connectivity. To complete the exercise, you will need an Azure subscription.

Create an Azure Database for MySQL single server

  1. Sign in to Azure Portal and search for Azure Database for MySQL.

    Search for Azure Database for MySQL in Azure portal
  2. In the new tab, select Add.

  3. In the Select Azure Database for MySQL deployment option window, select Single Server.

    Create an Azure Database for MySQL single server
  4. Then, configure the new database. Select:

    • Subscription.
    • Resource Group: Click Create new and enter the name of the new resource group.
    • Server name: Select a unique name.
    • Location: Select an available Azure region.
    • Compute + storage: We are going to use Basic, 1 vCore(s), 5 GB. Select Configure server. Then select the Basic tab, choose 1 vCore and 5 GB storage and click OK.
    • Admin username and password.
    Create an Azure Database for MySQL single server
  5. Select Review + create and wait for the server to be created (it may take several minutes). Once the deployment is complete, select Go to resource.

Create a server-level firewall rule

  1. On the MySQL server page, click Connection security in the left pane.

    Connection security
  2. Select Add client IP on the top toolbar and click Save to save this server-level firewall rule. (Before saving the configuration, verify your IP address.)

    Create a firewall rule
  3. Activate the Allow access to Azure services option.

Create a database via the Azure Cloud Shell

  1. Select the Azure Cloud Shell button on the top toolbar.

    Azure Cloud Shell
  2. If you are opening Azure Cloud Shell for the first time, you should choose your preferred shell experience and create a storage account.

    • Select Bash or PowerShell
    • Then select a subscription, a region and create a new resource group (or use an existing one), storage account and Microsoft Azure Files share.
    • Click Create storage.
  3. Run the following command in the terminal to connect to the server:

    1
    
    mysql --host=server.mysql.database.azure.com --user=username@server -p
    

    where

    • server is the name of your server.
    • username is your admin username.
  4. Enter your password. If you have successfully connected to the server, you will see the following statement in the terminal:

    1
    
    MySQL>
    
  5. Run the following SQL code to create a new database named demodb.

    1
    
    CREATE DATABASE demodb;
    
  6. Enter quit to quit mysql.

Next steps

In the next tutorial, you will use Python and Visual Studio Code to connect to your database.

You May Also Like