Quickstart: Azure Database for MySQL - Single Server

This quickstart guide walks you through the steps to create and connect to an Azure Database for MySQL - Single Server instance. This is the fastest way to get started with a managed MySQL database in Azure.

Note: Azure Database for MySQL - Single Server is a legacy offering. For new deployments, consider using Azure Database for MySQL - Flexible Server, which offers enhanced features and management capabilities.

Prerequisites

Step 1: Create an Azure Database for MySQL - Single Server

Using the Azure Portal

  1. Go to the Azure portal.
  2. In the search bar at the top, type Azure Database for MySQL and select it.
  3. Click Create.
  4. Select Single server.
  5. On the Basics tab:
    • Subscription: Choose your Azure subscription.
    • Resource group: Create a new one or select an existing one.
    • Server name: Enter a unique name for your MySQL server (e.g., mydemodbserver).
    • Location: Select the Azure region closest to you.
    • Version: Choose MySQL 5.7 or MySQL 8.0.
    • Compute + storage: Select a Pricing tier (e.g., Basic, General Purpose, Memory Optimized) and configure vCores and Storage size. For this quickstart, the Basic tier is sufficient.
    • Admin username: Enter the admin username for the server (e.g., mysqladmin).
    • Password: Enter and confirm a strong password.
  6. Click Review + create, then Create.
  7. Wait for the deployment to complete.

Step 2: Configure Firewall Rules

Allowing Client Connections

  1. Once the deployment is complete, navigate to your newly created Azure Database for MySQL server resource in the Azure portal.
  2. In the left-hand menu, under Settings, select Connection security.
  3. Under Firewall rules, click Add.
  4. Enter a Rule name (e.g., AllowLocalIP).
  5. Enter the Start IP and End IP addresses to allow your local machine's IP address. You can find your public IP address by searching "what is my IP" in a web search engine.
  6. Click Save.

You can also enable Allow access to Azure services if you plan to connect from other Azure services.

Step 3: Connect to the Server

Using the MySQL Command-Line Client

  1. From your local machine, open your command-line interface (CLI) or terminal.
  2. Use the following command to connect to your Azure Database for MySQL server. Replace your_server_name, your_admin_username, and your_password with your actual values.
mysql -h your_server_name.mysql.database.azure.com -u your_admin_username@your_server_name -p

When prompted, enter your admin password.

If the connection is successful, you will see the MySQL command prompt:

mysql>

Step 4: Create a Database and Table

Example SQL Commands

Once connected, you can execute SQL commands.

  1. Create a new database:
CREATE DATABASE quickstartdb;
  1. Select the new database:
USE quickstartdb;
  1. Create a table:
CREATE TABLE inventory (
    id INT NOT NULL AUTO_INCREMENT,
    name VARCHAR(255),
    quantity INT,
    PRIMARY KEY (id)
);
  1. Insert some data:
INSERT INTO inventory (name, quantity) VALUES
('item1', 10),
('item2', 25),
('item3', 15);
  1. Query the data:
SELECT * FROM inventory;

Next Steps

Congratulations! You have successfully created and connected to your Azure Database for MySQL - Single Server. You can now proceed to explore more advanced features and integrate it with your applications.