{"id":1837,"date":"2024-10-04T12:00:00","date_gmt":"2024-10-04T10:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/?p=1837"},"modified":"2026-08-28T11:00:49","modified_gmt":"2026-08-28T09:00:49","slug":"deploy-springboot-api-to-azure-with-mysql-database","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/deploy-springboot-api-to-azure-with-mysql-database\/","title":{"rendered":"Deploy SpringBoot API to Azure with MySQL Database"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><em>Learn how to deploy SpringBoot API to Azure with a MySQL database, GitHub Actions CI\/CD, Azure App Service, and secure deployment credentials.<\/em><\/p>\n\n\n<h2>TL;DR<\/h2>\n<ul>\n<li>\n<p><strong>Deploy SpringBoot API to Azure<\/strong> using Azure App Service and a MySQL database.<\/p>\n<\/li>\n<li>\n<p>Create an <strong>Azure App Service<\/strong> to host the Spring Boot REST API.<\/p>\n<\/li>\n<li>\n<p>Set up <strong>Azure MySQL Flexible Server<\/strong> and connect it to the Spring Boot application.<\/p>\n<\/li>\n<li>\n<p>Configure <strong>GitHub secrets and deployment credentials<\/strong> to securely connect your repository to Azure.<\/p>\n<\/li>\n<li>\n<p>Use a <strong>GitHub Actions workflow<\/strong> to create a CI\/CD pipeline that automatically deploys application changes to Azure.<\/p>\n<\/li>\n<\/ul>\n<p>In this tutorial, I will explain to you how to deploy Spring Boot REST API with MySQL database to MS Azure for free using the free tier. We would also, as a prerequisite have our application pushed to Github. In this way, we would also achieve a CI\/CD pipeline.<\/p>\n<p><strong>Prerequisites<\/strong><\/p>\n<ul>\n<li>You need to create an account in <a href=\"https:\/\/portal.azure.com\/?quickstart=true#home\" target=\"_blank\" rel=\"noopener\">Azure Portal<\/a><\/li>\n<li>Sign up for the Free Tier plan which provides you with a $200.00 credit in your billing account<\/li>\n<\/ul>\n<p>We would cover the following:<\/p>\n<ol>\n<li><a href=\"#t1\">Create the Azure App Service<\/a><\/li>\n<li><a href=\"#t2\">Create the Azure MySQL Database<\/a><\/li>\n<li><a href=\"#t3\">Obtain and Setup the Credentials<\/a><\/li>\n<li><a href=\"#t4\">Create and Update the Github Workflow<\/a><\/li>\n<li><a href=\"#t5\">Obtain the Workflow Yaml<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. Create the Azure App Service<\/strong><\/h4>\n<p>Sign in to Azure Portal and select App Services.<\/p>\n<figure id=\"attachment_15052\" class=\"wp-caption alignnone\" style=\"width: 740px;\" aria-describedby=\"caption-attachment-15052\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-01-at-15.17.02.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15052\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-01-at-15.17.02.png\" sizes=\"auto, (max-width: 740px) 100vw, 740px\" srcset=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-01-at-15.17.02.png 740w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-01-at-15.17.02-300x135.png 300w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-01-at-15.17.02-600x271.png 600w\" alt=\"Select App Service in Azure\" width=\"740\" height=\"334\" \/><\/a>\n<figcaption id=\"caption-attachment-15052\" class=\"wp-caption-text\">Select App Service in Azure<\/figcaption>\n<\/figure>\n<p>&nbsp;<\/p>\n<p>Click on Create -&gt; Web App<\/p>\n<p>Follow the steps to complete creating you web app (watch the video for the procedure)<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Create Azure MySQL Database<\/strong><\/h4>\n<p>We would have to create an Azure MySQL database. Then we would copy the database credentials and use it to update our application properties. Follow the procedure below:<\/p>\n<ul>\n<li>Search for Azure Databases for MySQL Servers<\/li>\n<li>Click on Create<\/li>\n<li>Choose Flexible Servers<\/li>\n<li>Click on Create an fill the required details<\/li>\n<li>Click on Review and Create and complete the process.<\/li>\n<li>Once the creation and deployment is complete<\/li>\n<li>Copy the name of the server and update the database url in the application.properties file in Spring Boot<\/li>\n<li>Connect to the database using this command<\/li>\n<\/ul>\n<pre style=\"margin: 0; line-height: 125%;\">mysql -h productdb2.mysql.database.azure.com -P 3306 -u rootuser -p\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Once connected, run the create database command and create the database specified in your application.properties file<\/p>\n<h4><strong id=\"t3\">3. Obtain and setup the Credentials\/Secrets<\/strong><\/h4>\n<p>Open the Azure terminal and run this command:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">az ad sp create-for-rbac --name \"myApp\" --role contributor \\\n    --scopes \/subscriptions\/{subscription-id}\/resourceGroups\/{resource-group} \\\n    --sdk-auth\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Now we have to copy the json generated in Step 2 above to Github.<\/p>\n<ul>\n<li>From your repo in Github, click on Settings.<\/li>\n<li>Select Environments from the left.<\/li>\n<li>Click on the environment<\/li>\n<li>Click on New Environment secret<\/li>\n<li>Enter the name as AZURE_CREDENTIALS<\/li>\n<li>In the value field, paste the secret you copied and then save.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Create and Update the Workflow<\/strong><\/h4>\n<p>We would have to create workflow yam file in Github. Follow the steps:<\/p>\n<ul>\n<li>From Github, click on the Actions tab and select New Workflow<\/li>\n<li>The click on <em>Set up a workflow yourself<\/em> link<\/li>\n<\/ul>\n<figure id=\"attachment_15068\" class=\"wp-caption aligncenter\" style=\"width: 300px;\" aria-describedby=\"caption-attachment-15068\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.20.55.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-15068 size-medium\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.20.55-300x146.png\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" srcset=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.20.55-300x146.png 300w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.20.55-1024x500.png 1024w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.20.55-768x375.png 768w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.20.55-1536x750.png 1536w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.20.55-600x293.png 600w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.20.55.png 1786w\" alt=\"Set up a new workflow yourself\" width=\"300\" height=\"146\" \/><\/a>\n<figcaption id=\"caption-attachment-15068\" class=\"wp-caption-text\">Set up a new workflow yourself<\/figcaption>\n<\/figure>\n<p>This would open an empty workflow yaml file. You will obtain what you\u2019ll place in this file from Azure.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. Obtain the Workflow Yaml<\/strong><\/h4>\n<p>Follow the steps below:<\/p>\n<p>Open your web app in Azure portal<\/p>\n<p>Click on Deployments as shown below:<\/p>\n<figure id=\"attachment_15069\" class=\"wp-caption alignnone\" style=\"width: 1024px;\" aria-describedby=\"caption-attachment-15069\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.37.05.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-15069 size-large\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.37.05-1024x528.jpg\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.37.05-1024x528.jpg 1024w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.37.05-300x155.jpg 300w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.37.05-768x396.jpg 768w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.37.05-1536x793.jpg 1536w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.37.05-2048x1057.jpg 2048w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.37.05-600x310.jpg 600w\" alt=\"Configuring webapp deployment in Azure\" width=\"1024\" height=\"528\" \/><\/a>\n<figcaption id=\"caption-attachment-15069\" class=\"wp-caption-text\">Configuring webapp deployment in Azure<\/figcaption>\n<\/figure>\n<p>&nbsp;<\/p>\n<p>Click on the Deployment Center link<\/p>\n<p>Make the selections as shown below in the figure below:<\/p>\n<figure id=\"attachment_15070\" class=\"wp-caption alignnone\" style=\"width: 1024px;\" aria-describedby=\"caption-attachment-15070\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-15070 size-large\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1024x861.jpg\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1024x861.jpg 1024w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-300x252.jpg 300w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-768x646.jpg 768w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1536x1292.jpg 1536w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-600x505.jpg 600w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59.jpg 1800w\" alt=\"Github deployment settings\" width=\"1024\" height=\"861\" \/><\/a>\n<figcaption id=\"caption-attachment-15070\" class=\"wp-caption-text\">Github deployment settings<\/figcaption>\n<\/figure>\n<p>&nbsp;<\/p>\n<p>In the authentication settings, select User-Assigned Identity<\/p>\n<p>Leave the other entries with their default values<\/p>\n<figure id=\"attachment_15071\" class=\"wp-caption alignnone\" style=\"width: 1024px;\" aria-describedby=\"caption-attachment-15071\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-15071 size-large\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1-1024x861.jpg\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1-1024x861.jpg 1024w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1-300x252.jpg 300w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1-768x646.jpg 768w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1-1536x1292.jpg 1536w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1-600x505.jpg 600w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1.jpg 1800w\" alt=\"Deployment authentication settings\" width=\"1024\" height=\"861\" \/><\/a>\n<figcaption id=\"caption-attachment-15071\" class=\"wp-caption-text\">Deployment authentication settings<\/figcaption>\n<\/figure>\n<p>&nbsp;<\/p>\n<p>Then click on <strong><em>Preview File<\/em><\/strong>.<\/p>\n<p>Copy the the output to the Github workflow file.<\/p>\n<figure id=\"attachment_15072\" class=\"wp-caption alignnone\" style=\"width: 1024px;\" aria-describedby=\"caption-attachment-15072\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.22.12-scaled.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-15072 size-large\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.22.12-1024x600.jpg\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.22.12-1024x600.jpg 1024w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.22.12-300x176.jpg 300w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.22.12-768x450.jpg 768w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.22.12-1536x899.jpg 1536w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.22.12-2048x1199.jpg 2048w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.22.12-600x351.jpg 600w\" alt=\"Output of Github Deployment configuration \" width=\"1024\" height=\"600\" \/><\/a>\n<figcaption id=\"caption-attachment-15072\" class=\"wp-caption-text\">Output of Github Deployment configuration<\/figcaption>\n<\/figure>\n<p>&nbsp;<\/p>\n<p><strong>Enable Public Access<\/strong><\/p>\n<ul>\n<li>Navigate to your app in Azure<\/li>\n<li>Click on Networking<\/li>\n<li>Check and make sure it\u2019s Enabled<\/li>\n<\/ul>\n<h2>FAQs<\/h2>\n<p><strong>Can I deploy a Spring Boot API to Azure?<\/strong><\/p>\n<p>Yes. This tutorial uses Azure App Service to host the Spring Boot REST API and Azure MySQL for the application&#8217;s database.<\/p>\n<p><strong>What Azure service is used to host the Spring Boot API?<\/strong><\/p>\n<p>The tutorial uses <strong>Azure App Service<\/strong>, which provides a managed environment for hosting the Spring Boot application.<\/p>\n<p><strong>How do I connect Spring Boot to Azure MySQL?<\/strong><\/p>\n<p>Create an Azure MySQL Flexible Server, obtain its server details and credentials, and update the Spring Boot database configuration with the Azure MySQL connection information.<\/p>\n<p><strong>Can GitHub automatically deploy my Spring Boot application to Azure?<\/strong><\/p>\n<p>Yes. GitHub Actions can be configured as a CI\/CD pipeline so changes pushed to the repository can trigger deployment to Azure App Service.<\/p>\n<p><strong>Where should Azure deployment credentials be stored?<\/strong><\/p>\n<p>The tutorial stores the Azure credentials as a <strong>GitHub environment secret<\/strong>, rather than placing sensitive credentials directly in the workflow file.<\/p>\n<p><strong>Can I use the Azure free tier for this tutorial?<\/strong><\/p>\n<p>The original tutorial is designed around Azure&#8217;s free-tier\/free-credit offering. Azure pricing and free-tier eligibility can change, so check the current Azure terms before deploying.<\/p>\n<h2>Final Thoughts<\/h2>\n<p>Deploying a Spring Boot API to Azure brings together several important cloud and DevOps concepts: managed application hosting, cloud databases, deployment credentials, and CI\/CD automation.<\/p>\n<p>The workflow in this tutorial starts with an Azure App Service and MySQL database, connects the application to the database, and then uses GitHub Actions to automate deployment. This gives you more than a hosted API \u2014 it provides a foundation for continuously delivering changes from your source repository to Azure.<\/p>\n<p>As you move beyond a basic deployment, the next step is to strengthen the setup with proper secret management, environment-specific configuration, monitoring, database backups, HTTPS, and a more robust CI\/CD workflow. The core process remains the same: <strong>build, configure, deploy, and automate<\/strong>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Learn how to deploy SpringBoot API to Azure with a MySQL database, GitHub Actions CI\/CD, Azure App Service, and secure deployment credentials.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[311],"tags":[],"class_list":["post-1837","post","type-post","status-publish","format-standard","hentry","category-sql"],"acf":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=1837"}],"version-history":[{"count":4,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1837\/revisions"}],"predecessor-version":[{"id":2536,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1837\/revisions\/2536"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}