Azure MySQL in App for App services
Tags: azure, azureservices, mysql, azurewebsites
Published: 2020-03-02 11:56:30

---
title: Azure MySQL in App for App services
published: true
date: 2018-11-10 18:59:42 UTC
tags: azure,azure-services,mysql,azure-websites
canonical_url: 
---

When you need a database for your website, why purchase a separate database service?

![](https://cdn-images-1.medium.com/max/400/1*Yfki03qFEIyx1vIPvgzh3A.jpeg)<figcaption>MySQL in app in Azure app service</figcaption>

MySQL in app was announced in March, 2017. Azure provides MySQL within your web app (App service), every web app in Azure has MySQL in app as an option. For [Windows](https://azure.microsoft.com/en-us/blog/mysql-in-app-preview-app-service/) hosting MySQL in app service is available.

Note that, this can be used for small projects or dev/test projects, when moving to production you might want to consider [Azure database for MySQL](https://azure.microsoft.com/en-in/services/mysql/), which is Enterprise-ready, fully managed community MySQL database.

**Getting Started :**

This option comes disabled by default in every app service you create. In order to have MySQL in app database, you need to enable it from your web app settings, as shown below :

![](https://cdn-images-1.medium.com/max/1024/1*1QdWOWmE1XuRDynvz87GJQ.png)<figcaption>Enabling MySQL in app for Azure app services</figcaption>

After enabling it, wait for couple of minutes to enable certain services for your web app, which includes some cool stuff such as [phpmyadmin](https://www.phpmyadmin.net/).

After enabling it, you’ll see the screen as below :

![](https://cdn-images-1.medium.com/max/1015/1*N5FyoH-D79YEnwuFUbU_6A.png)<figcaption>MySQL in App Settings</figcaption>

To secure the connection between your app and your MySQL Database, you have an environment variable named “MYSQLCONNSTR\_localdb” which contains value as connection string for your in app MySQL database.

Now, access your phpmyadmin go to : [https://<yoursite>.scm.azurewebsites.net/phpmyadmin](https://yoursite.scm.azurewebsites.net/phpmyadmin). You have phpmyadmin now, which means you can start using MySQL database.

You can connect to in app MySQL as below :

```
<?php 
    //below will give the whole connectionstring in a single string
    $conn = getenv("MYSQLCONNSTR\_localdb"); 

    //Let's split it and decorate it in an array
    $conarr2 = explode(";",$conn); 
    $conarr = array();
    foreach($conarr2 as $key=>$value){
        $k = substr($value,0,strpos($value,'='));
        $conarr[$k] = substr($value,strpos($value,'=')+1);
    }
    // $conarr is an array of values of connection string
    print\_r($conarr); 
?>
```

There you go, you have now connection details to MySQL in app available within your app service, now you can use **mysqli\_\*** functions or **PDO** to perform CRUD operations and much more.

Hope this article has walked you clear with the concepts of MySQL in app for Azure app services. In case you want to connect with me you can DM me in twitter at [https://twitter.com/niravmadariya](https://twitter.com/niravmadariya)

Please don’t forget to clap for the article if you liked reading it. See you soon with more concepts in Azure :)

**Next :**

- Ask MSPs (Microsoft Student Partners) what to do next
- Start Learning [Azure Cloud Devlopment](https://docs.microsoft.com/en-us/learn/#!jobf=Developer&lang=1033)
- See [Azure Documentation](https://docs.microsoft.com/en-us/azure/)