{"id":1837,"date":"2026-05-22T14:39:11","date_gmt":"2026-05-22T12:39:11","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/?p=1837"},"modified":"2026-05-22T14:39:11","modified_gmt":"2026-05-22T12:39:11","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":"<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\" aria-describedby=\"caption-attachment-15052\" style=\"width: 740px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-01-at-15.17.02.png\"><img decoding=\"async\" loading=\"lazy\" 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\" alt=\"Select App Service in Azure\" width=\"740\" height=\"334\" \/><\/a><figcaption id=\"caption-attachment-15052\" class=\"wp-caption-text\">Select App Service in Azure<\/figcaption><\/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\r\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 \\\r\n    --scopes \/subscriptions\/{subscription-id}\/resourceGroups\/{resource-group} \\\r\n    --sdk-auth\r\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\" aria-describedby=\"caption-attachment-15068\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.20.55.png\"><img decoding=\"async\" loading=\"lazy\" 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\" alt=\"Set up a new workflow yourself\" width=\"300\" height=\"146\" \/><\/a><figcaption id=\"caption-attachment-15068\" class=\"wp-caption-text\">Set up a new workflow yourself<\/figcaption><\/figure>\n<p>This would open an empty workflow yaml file. You will obtain what you&#8217;ll 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\" aria-describedby=\"caption-attachment-15069\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-00.37.05.jpg\"><img decoding=\"async\" loading=\"lazy\" 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\" alt=\"Configuring webapp deployment in Azure\" width=\"1024\" height=\"528\" \/><\/a><figcaption id=\"caption-attachment-15069\" class=\"wp-caption-text\">Configuring webapp deployment in Azure<\/figcaption><\/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\" aria-describedby=\"caption-attachment-15070\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59.jpg\"><img decoding=\"async\" loading=\"lazy\" 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\" alt=\"Github deployment settings\" width=\"1024\" height=\"861\" \/><\/a><figcaption id=\"caption-attachment-15070\" class=\"wp-caption-text\">Github deployment settings<\/figcaption><\/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\" aria-describedby=\"caption-attachment-15071\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.16.59-1.jpg\"><img decoding=\"async\" loading=\"lazy\" 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\" alt=\"Deployment authentication settings\" width=\"1024\" height=\"861\" \/><\/a><figcaption id=\"caption-attachment-15071\" class=\"wp-caption-text\">Deployment authentication settings<\/figcaption><\/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\" aria-describedby=\"caption-attachment-15072\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2024\/10\/Screenshot-2024-10-04-at-01.22.12-scaled.jpg\"><img decoding=\"async\" loading=\"lazy\" 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\" alt=\"Output of Github Deployment configuration \" width=\"1024\" height=\"600\" \/><\/a><figcaption id=\"caption-attachment-15072\" class=\"wp-caption-text\">Output of Github Deployment configuration<\/figcaption><\/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&#8217;s Enabled<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<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 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[414],"tags":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1837"}],"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":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1837\/revisions"}],"predecessor-version":[{"id":1838,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1837\/revisions\/1838"}],"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}]}}