Quickstart: Azure Database for MySQL - Single Server
This quickstart guide walks you through the steps to create and connect to an Azure Database for MySQL - Single Server instance. This is the fastest way to get started with a managed MySQL database in Azure.
Note: Azure Database for MySQL - Single Server is a legacy offering. For new deployments, consider using Azure Database for MySQL - Flexible Server, which offers enhanced features and management capabilities.
Prerequisites
- An Azure account. If you don't have one, sign up for a free account.
- Your local machine needs to have the MySQL client tools installed.
Step 1: Create an Azure Database for MySQL - Single Server
Using the Azure Portal
- Go to the Azure portal.
- In the search bar at the top, type
Azure Database for MySQLand select it. - Click Create.
- Select Single server.
- On the Basics tab:
- Subscription: Choose your Azure subscription.
- Resource group: Create a new one or select an existing one.
- Server name: Enter a unique name for your MySQL server (e.g.,
mydemodbserver). - Location: Select the Azure region closest to you.
- Version: Choose
MySQL 5.7orMySQL 8.0. - Compute + storage: Select a Pricing tier (e.g., Basic, General Purpose, Memory Optimized) and configure vCores and Storage size. For this quickstart, the Basic tier is sufficient.
- Admin username: Enter the admin username for the server (e.g.,
mysqladmin). - Password: Enter and confirm a strong password.
- Click Review + create, then Create.
- Wait for the deployment to complete.
Step 2: Configure Firewall Rules
Allowing Client Connections
- Once the deployment is complete, navigate to your newly created Azure Database for MySQL server resource in the Azure portal.
- In the left-hand menu, under Settings, select Connection security.
- Under Firewall rules, click Add.
- Enter a Rule name (e.g.,
AllowLocalIP). - Enter the Start IP and End IP addresses to allow your local machine's IP address. You can find your public IP address by searching "what is my IP" in a web search engine.
- Click Save.
You can also enable Allow access to Azure services if you plan to connect from other Azure services.
Step 3: Connect to the Server
Using the MySQL Command-Line Client
- From your local machine, open your command-line interface (CLI) or terminal.
- Use the following command to connect to your Azure Database for MySQL server. Replace
your_server_name,your_admin_username, andyour_passwordwith your actual values.
mysql -h your_server_name.mysql.database.azure.com -u your_admin_username@your_server_name -p
When prompted, enter your admin password.
If the connection is successful, you will see the MySQL command prompt:
mysql>
Step 4: Create a Database and Table
Example SQL Commands
Once connected, you can execute SQL commands.
- Create a new database:
CREATE DATABASE quickstartdb;
- Select the new database:
USE quickstartdb;
- Create a table:
CREATE TABLE inventory (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255),
quantity INT,
PRIMARY KEY (id)
);
- Insert some data:
INSERT INTO inventory (name, quantity) VALUES
('item1', 10),
('item2', 25),
('item3', 15);
- Query the data:
SELECT * FROM inventory;
Next Steps
Congratulations! You have successfully created and connected to your Azure Database for MySQL - Single Server. You can now proceed to explore more advanced features and integrate it with your applications.
- Explore tutorials for common tasks.
- Learn about key concepts.
- Discover how to manage your server.