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
- Open the Azure portal and select Create a resource → Databases → Azure Database for MariaDB.
- 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
- Server name:
- Click **Review + create**, then **Create**. Wait for deployment to finish.
- In the server overview, copy the Server name (e.g.,
my-mariadb-server.mariadb.database.azure.com
). - 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
- Test connection – you should see “Successfully made the MySQL connection”.
- 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
- 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
- Resource group:
- Under Deployment Center, select GitHub and choose the official WordPress repository. Follow the wizard to complete deployment.
- After the site is live, navigate to
https://my-wp-app.azurewebsites.net
. The WordPress setup wizard appears. - 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_
- Complete the WordPress installation, set your site title and admin user.
- 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
- Create a new GitHub repository (or use an existing one) and add a folder
db/migrations
. - 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 );
- 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;
- 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
- 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
- Open your MariaDB server in the Azure portal.
- Select **Backup** under the **Settings** blade.
- Toggle **Geo‑redundant backup** to **On**.
- Set **Backup retention days** (e.g., 35 days) and click **Save**.
Perform a point‑in‑time restore
- In the **Backup** blade, click **Restore**.
- Choose **Point‑in‑time** and select a timestamp within the retention period.
- Provide a new server name (e.g.,
my-mariadb-restore
) and keep other settings the same. - Click **OK** to start the restore operation.
- 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
- Create (or use) an existing VNet, e.g.,
my-vnet
with a subnetdb-subnet
. - In the MariaDB server blade, select **Networking** → **Virtual network rules**.
- Click **Add existing virtual network**, choose the subscription, VNet, and subnet, then click **Add**.
- Set **Public network access** to **Disabled** to enforce VNet‑only access.
- 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
- If the connection succeeds, your server is now fully isolated to the virtual network.