Setup MySQL and Service Deployment in Azure

Aashik Ahamed
5 min readAug 15, 2020

Hello there, In my previous article Full Stack Application Deployment in Azure I have given the overview of my application to deploy in Azure. So in this article we will see how to deploy our Permanent-Product Service in Azure.

Permanent-Product Service access the database and do some CRUD operations like Add,View,Update and Delete products. We are using MySQL database in our application.So first we need to setup the MySQL database server in Azure. So let’s setup it first.

Setting up a MySQL server in Azure

  • First Login to your Azure Portal
  • Then Select Azure Database for MySQL in the Databases category.

In order to setup a MySQL server we need provide some configurations.

  • Resource Group- Select/Create a new Resource Group.
  • Server name- Give a unique name for your MySQL server.
  • Location- Select a region in which you need to spin up the server.
  • Compute Storage- Select the storage based on your application’s need and also keep a look at the costing as well.
  • Then give Admin username and password to access the database server.

Then Click Review and Create.

So now we have created our Azure My SQL database server. Now in the portal we can see that our MySQL is up and running.So next will see how to create the database using the created database server.

To access the database server we need to setup the firewall. To access from your MySQL Workbench then give your machine IP. Your can setup your firewall for specific IP’s that need to access you server.Also we are accessing the database server from Azure App Service, so we need allow access to Azure services as well.

Go to the Connection Security and click on Add current client IP to access the database server from our local machine. Also enable YES to Allow access to Azure services, then only we can connect from Permanent-Product Service to access the Database..

Then open your MySQL workbench from your machine and create a New Connection.

Add your server name, username and login to the server using the password of the created server.

Then create the database using the SQL command.

create database demo_db;

So now we have created a database in the Azure MySQL server. So next will see the steps to deploy the Permanent-Product Service.

So Let’s Start Deploy !!!

Go to my Github repository and clone/download my project.

From the root directory move to /my-demo/permanent-product module in which our Permanent-Product Service resides.

Go to the application.properties file and change the following database configurations with the MySQL server you have created.

We will build the Permanent-Product JAR and deploy it to Azure App Service. So Open the Permanent-Product pom.xml and add the following maven dependency.

<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>1.9.1</version>
</plugin>

We are deploying the JAR using Azure cli, So if you don’t have Azure cli installed then install it. Look Azure Cli installation here

Open Azure cli and first login to the cli using the following command and it will prompt to the Azure login page in a browser.

az login

Provide your Azure account login credentials and log in. After a successfull login you would see

Then to add the deployment configurations run the following code

mvn azure-webapp:config

After the Successful Build the configurations will be added to your pom.xml. You can change the configurations from your pom.xml. You can change the appName,pricingTier,location etc as per your need. Also add this app settings to your configuartion as well.

<appSettings>           
<property>
<name>JAVA_OPTS</name>
<value>-Dserver.port=80</value>
</property>
</appSettings>

Then to deploy your app in Azure App Service first clean and then deploy .

mvn clean packagemvn azure-webapp:deploy

After successful deployment you can see this in your command line

So now we have deployed our Permanent-Product in Azure App Service.So in the Azure App Services we can view the deployed service.

So now it’s all done!!!. Let’s test our deployment of Permanent-Product Service using the PostMan.

  • Add a product- POST : /product
  • View all products - GET : /products

So that’s it we have setup the MySQL server and deployed our Permanent Product Service in Azure. So next we will see how to deploy of Message-Service in Azure Function.

You can watch my

You can view my next article Azure App Function

References

--

--