How to Connect with Managed Identity to Azure Database for MySQL Flexible Server

Sekar, Anbu 26 Reputation points
2023-07-10T12:46:38.78+00:00

I have web app service in Azure written in PHP. I also have database which is Azure Database for MySQL Flexible Server.

I have enabled AD authentication in MySQL flexible server. I have also enabled user/system managed identity in the Web app service.

How to connect the MySQL flexible Server using managed identity, could you please shared the approach and documentation if any. I have tried my best to find it. Any help would be appreciated.

Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
880 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,160 questions
{count} votes

2 answers

Sort by: Most helpful
  1. TP 101.8K Reputation points
    2023-07-10T20:11:00.5066667+00:00

    Hi Anbu,

    The normal pattern is to make HTTP GET request to the local token service from your code running on App Services. The response will give you the token you need to connect to the service (in this case Azure Database for MySQL Flexible Server). Please see article below:

    https://learn.microsoft.com/en-us/azure/app-service/overview-managed-identity?tabs=portal%2Chttp#connect-to-azure-services-in-app-code

    Based on what is written in below article you would use the access token you retrieved above as the password when connecting to the database:

    https://learn.microsoft.com/en-us/azure/mysql/single-server/how-to-connect-with-managed-identity#connecting-using-managed-identity-in-c

    Please click Accept Answer if the above was helpful. If something I wrote above is unclear or you need additional assistance please add a comment below.

    Thanks.

    -TP

    0 comments No comments

  2. GeethaThatipatri-MSFT 29,502 Reputation points Microsoft Employee
    2023-07-11T14:04:27.86+00:00

    Hi, @Sekar, Anbu We do not have documentation specific to PHP using managed identity however you can use the same idea that we have written in .net code

    https://techcommunity.microsoft.com/t5/azure-database-for-mysql-blog/how-to-connect-to-azure-database-for-mysql-using-managed/ba-p/1518196

    I hope this should help.

    Please let me know if you have any questions on the above blog.

    Regards

    Geetha

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.