A VS Code extension for connecting to Azure Database for MySQL Flexible Server using Microsoft Entra ID (formerly Azure AD) authentication.
Features
Entra ID Authentication: Automatically acquires and refreshes tokens using your Azure sign-in
Connection Management: Save and manage multiple MySQL connections
Query Editor: Execute SQL queries with results displayed in a table
Object Explorer: Browse tables and columns in the sidebar
Prerequisites
Azure Resources Extension: Install the Azure Resources extension
Sign in to Azure: Use the "Azure: Sign In" command in VS Code
Azure Database for MySQL: A Flexible Server instance with Entra ID authentication enabled
Setup Azure MySQL for Entra ID Auth
Before using this extension, ensure your Azure Database for MySQL Flexible Server is configured:
In the Azure Portal, go to your MySQL Flexible Server
Navigate to Security → Authentication
Set authentication to MySQL and Microsoft Entra authentication (or Entra only)
Add a Microsoft Entra Admin (user or group)
Create database users for Entra identities:
-- Connect as the Entra admin, then create users:
CREATE USER 'user@tenant.onmicrosoft.com' IDENTIFIED BY 'token';
GRANT ALL PRIVILEGES ON mydb.* TO 'user@tenant.onmicrosoft.com';
Usage
Add a Connection
Click the Azure MySQL icon in the Activity Bar
Click the + button or run "Azure MySQL: Add Connection"
Enter connection details:
Name: A friendly name for the connection
Host: Your server hostname (e.g., myserver.mysql.database.azure.com)
Port: Usually 3306
Database: The database name
User: Your Entra ID username (e.g., user@tenant.onmicrosoft.com)
SSL: Yes (recommended for Azure)
Connect
Right-click a connection and select Connect
The extension will automatically acquire an Entra ID token
Once connected, the connection icon turns green and shows tables
Run Queries
Right-click a connected server and select New Query
Enter your SQL in the query editor
Click Run Query or press Ctrl+Enter / Cmd+Enter
Results display in a table below
How Authentication Works
When you connect, the extension requests an access token for Azure Database for MySQL
It uses VS Code's built-in Azure authentication (via the Azure Account extension)
Falls back to Azure CLI (az login) if VS Code auth is unavailable
Tokens are automatically refreshed before expiry (tokens valid 5-60 minutes)
Development
Build
cd azure-mysql-entra
npm install
npm run compile
Run in Debug Mode
Open the extension folder in VS Code
Press F5 to launch the Extension Development Host
The extension will be available in the new VS Code window
Package as VSIX
npm install -g @vscode/vsce
vsce package
This creates azure-mysql-entra-0.1.0.vsix which can be installed locally.
Troubleshooting
"Failed to get Azure token"
Ensure you're signed in to Azure: Run "Azure: Sign In" command
Or sign in via CLI: az login
"Access denied for user"
Verify the user exists in the MySQL database
Check that Entra ID authentication is enabled on the server
Ensure your Entra ID user has the correct permissions