Cannot connect to Azure Database for MySQL Flexible Server from Cloud Shell.

abdul shakoor 0 Reputation points
2025-10-15T01:55:57.49+00:00

I am unable to connect to my Azure Database for MySQL Flexible Server, and I need help troubleshooting a persistent network connectivity issue.

Problem Description

I am trying to connect to my Azure Database for MySQL Flexible Server with the hostname sumradb.mysql.database.azure.com from a PHP application running on a server with the IP address 20.198.197.154.

The connection from my PHP application fails with the following error: Failed to connect to database: SQLSTATE[HY000] [1045] Access denied for user 'sumradb@sumradb'@'20.198.197.154' (using password: YES)

To fix this, I have attempted to connect from the Azure Cloud Shell, but I am now facing a new error at the network level. The command and the error message are as follows:

Command:

az mysql flexible-server connect --admin-user sumradb --name sumradb.mysql.database.azure.com

Error:

Failed connection to sumradb.mysql.database.azure.com. Check error and validate firewall and public access or virtual network settings. Unable to connect to flexible server: (2003, "Can't connect to MySQL server... errno 2 Name or service not known")

Troubleshooting Steps I Have Taken

Firewall Rules: I have verified that the firewall rules in the Azure portal on the Networking page for my sumradb server are configured to allow my application's IP address (20.198.197.154).

Azure Services Access: The option "Allow public access from any Azure service within Azure to this server" is also enabled.

Server Status: I have confirmed that the database server's status in the Azure portal is Ready.

Authentication: I have also tried to create a new user via MySQL Workbench using the GRANT command, but I am receiving a Error Code: 1410. You are not allowed to create a user with GRANT error, suggesting a privilege issue with my admin account itself.

Despite these steps, the Cloud Shell cannot resolve the server's name, which is preventing me from creating a new user to resolve the initial Access denied error.

My Question

Why is the Cloud Shell unable to resolve the hostname of my Flexible Server, and what is causing the Name or service not known error, given that my networking settings are correct?

Azure Database for MySQL
{count} votes

1 answer

Sort by: Most helpful
  1. Tony Dinh (WICLOUD CORPORATION) 3,585 Reputation points Microsoft External Staff
    2025-10-15T06:32:37.9066667+00:00

    Hello @abdul shakoor !

    This issue is not related to firewall rules or MySQL authentication. What you’re seeing is a DNS resolution failure. In other words, Cloud Shell cannot translate sumradb.mysql.database.azure.com into an IP address.

    The key detail is that the --name parameter in az mysql flexible-server connect expects only the server name, not the full FQDN. Example for a correct command:

    az mysql flexible-server connect --admin-user sumradb --name sumradb
    

    When you pass the full FQDN, the CLI appends .mysql.database.azure.com again, producing an invalid hostname that DNS cannot resolve.

    If your Flexible Server is configured with private access only (inside a VNet), Cloud Shell (which runs in a Microsoft-managed VNet) will never be able to reach it. In that case, you have two options:

    • Enable public access on the Flexible Server:
      • Go to the Azure portal → Networking → confirm that Public access (allowed) is selected.
      • If it’s set to Private access (VNet Integration), Cloud Shell cannot connect. You’ll need a VM in the same VNet.
    • Use a Bastion host or jumpbox VM inside the VNet to connect.

    On your PHP app: Access denied for user

    This is a MySQL authentication problem, separate from the DNS issue. The error:

    Access denied for user 'sumradb@sumradb'@'20.198.197.154'
    

    This indicates that the server is reachable, but either the password is incorrect or the user mapping is invalid. To resolve this, you can try:

    • Double-check that you’re using the admin password you set when creating the server.
    • If you’ve reset the password in the portal, make sure your PHP app is updated with the new one.

    Regarding the GRANT error (1410):

    Flexible Server’s admin account is not a full MySQL SUPER user. It has elevated privileges but cannot use WITH GRANT OPTION. To create application users, use:

    CREATE USER 'appuser'@'%' IDENTIFIED BY 'StrongPassword!';
    GRANT ALL PRIVILEGES ON *.* TO 'appuser'@'%';
    

    I hope this helps!


Your answer

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