```html Azure Database for MariaDB – Tutorials
Microsoft

Azure Database for MariaDB

Azure Database for MariaDB – Tutorials

Learn how to build, deploy, and manage MariaDB workloads on Azure with step‑by‑step guides, sample code, and best‑practice recommendations.

Table of contents

1. Deploy a MariaDB server and connect with MySQL Workbench

This tutorial shows how to create an Azure Database for MariaDB instance using the Azure portal and connect to it with MySQL Workbench.

Steps

  1. Open the Azure portal and select Create a resource → Databases → Azure Database for MariaDB.
  2. Configure the server:
    • Server name: my-mariadb-server
    • Location: Choose a region close to you
    • Version: 10.5
    • Compute + storage: Choose Basic, 2 vCores, 5 GB storage
    • Authentication: Set admin username and password
  3. Click **Review + create**, then **Create**. Wait for deployment to finish.
  4. In the server overview, copy the Server name (e.g., my-mariadb-server.mariadb.database.azure.com).
  5. Open MySQL Workbench, click **+** to create a new connection, and fill in:
    Connection Name: Azure MariaDB
    Hostname: my-mariadb-server.mariadb.database.azure.com
    Port: 3306
    Username: adminuser@my-mariadb-server
    Password: your_password
  6. Test connection – you should see “Successfully made the MySQL connection”.
  7. Run a sample query:
    CREATE DATABASE sampledb;
    USE sampledb;
    CREATE TABLE hello (id INT PRIMARY KEY AUTO_INCREMENT, greeting VARCHAR(100));
    INSERT INTO hello (greeting) VALUES ('Hello Azure MariaDB!');
    SELECT * FROM hello;

Congratulations! You have a running MariaDB server and a working connection from your local machine.

2. Build a WordPress site on Azure App Service using MariaDB

Deploy a fully managed WordPress site backed by Azure Database for MariaDB.

Prerequisites

  • Azure subscription
  • Existing MariaDB server (you can reuse the one from Tutorial 1)
  • WordPress admin credentials (you will create them later)

Steps

  1. In the Azure portal, create a new App Service:
    • Resource group: wordpress-rg
    • Name: my-wp-app
    • Publish: Code
    • Runtime stack: PHP 8.1
    • Region: same as your MariaDB server
  2. Under Deployment Center, select GitHub and choose the official WordPress repository. Follow the wizard to complete deployment.
  3. After the site is live, navigate to https://my-wp-app.azurewebsites.net. The WordPress setup wizard appears.
  4. Enter database details:
    Database name: wordpress
    Username: adminuser@my-mariadb-server
    Password: your_password
    Database host: my-mariadb-server.mariadb.database.azure.com
    Table prefix: wp_
  5. Complete the WordPress installation, set your site title and admin user.
  6. Verify the site loads correctly and you can log in to the WP admin dashboard.

3. Set up CI/CD with GitHub Actions to deploy database schema changes

This tutorial demonstrates how to automate schema migrations using GitHub Actions and the mariadb client.

Steps

  1. Create a new GitHub repository (or use an existing one) and add a folder db/migrations.
  2. Place your SQL migration files in that folder, e.g., 001-create-orders.sql:
    CREATE TABLE orders (
        id BIGINT PRIMARY KEY AUTO_INCREMENT,
        customer_id BIGINT NOT NULL,
        order_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
    );
  3. Add a secret to the repository named MYSQL_CONNECTION_STRING with value:
    Server=my-mariadb-server.mariadb.database.azure.com;Port=3306;Database=sampledb;Uid=adminuser@my-mariadb-server;Pwd=YOUR_PASSWORD;SslMode=Preferred;
  4. Create .github/workflows/db-deploy.yml:
    name: Deploy DB migrations
    on:
      push:
        paths:
          - 'db/migrations/**'
    jobs:
      migrate:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout repo
            uses: actions/checkout@v4
    
          - name: Install MariaDB client
            run: sudo apt-get update && sudo apt-get install -y mariadb-client
    
          - name: Run migrations
            env:
              MYSQL_CONNECTION_STRING: ${{ secrets.MYSQL_CONNECTION_STRING }}
            run: |
              for file in db/migrations/*.sql; do
                echo "Applying $file..."
                mysql "$MYSQL_CONNECTION_STRING" < "$file"
              done
  5. Commit and push the workflow file. GitHub Actions will run and apply any new migration scripts to your Azure MariaDB server automatically.

4. Configure Geo‑redundant backup and point‑in‑time restore

Ensure your data is protected across regions and can be restored to any point within the retention window.

Enable Geo‑redundant backup

  1. Open your MariaDB server in the Azure portal.
  2. Select **Backup** under the **Settings** blade.
  3. Toggle **Geo‑redundant backup** to **On**.
  4. Set **Backup retention days** (e.g., 35 days) and click **Save**.

Perform a point‑in‑time restore

  1. In the **Backup** blade, click **Restore**.
  2. Choose **Point‑in‑time** and select a timestamp within the retention period.
  3. Provide a new server name (e.g., my-mariadb-restore) and keep other settings the same.
  4. Click **OK** to start the restore operation.
  5. When completed, connect to the new server using the same credentials to verify data integrity.

5. Secure your server with Virtual Network service endpoints

Restrict access to your MariaDB server so that only resources within a specific Azure Virtual Network can connect.

Steps

  1. Create (or use) an existing VNet, e.g., my-vnet with a subnet db-subnet.
  2. In the MariaDB server blade, select **Networking** → **Virtual network rules**.
  3. Click **Add existing virtual network**, choose the subscription, VNet, and subnet, then click **Add**.
  4. Set **Public network access** to **Disabled** to enforce VNet‑only access.
  5. From a VM inside the subnet, install the MariaDB client and test the connection:
    sudo apt-get install mariadb-client
    mysql -h my-mariadb-server.mariadb.database.azure.com -u adminuser@my-mariadb-server -p
  6. If the connection succeeds, your server is now fully isolated to the virtual network.
```