Getting Started with Azure Database for MySQL
This tutorial will guide you through the essential steps to set up and start using Azure Database for MySQL, a fully managed relational database service built on the MySQL community edition database engine.
1. Create an Azure Database for MySQL Server
Follow these steps to provision your MySQL server instance in Azure:
- Sign in to the Azure portal.
- Click Create a resource in the top-left corner.
- In the search bar, type Azure Database for MySQL and select it.
- Click Create.
- Choose the deployment option: Single server, Flexible server, or Hyperscale (Citus). For this tutorial, we'll use Single server.
- Fill in the required information: Subscription, Resource group, Server name, Location, Version, Compute + storage, Admin username, and Password.
- Click Review + create, then Create.
2. Connect to your MySQL Server
Once your server is deployed, you can connect to it using various MySQL client tools.
Using MySQL Workbench
To connect using MySQL Workbench:
- Open MySQL Workbench.
- Click the + icon to create a new connection.
- Enter the connection details:
- Connection Name: e.g., MyAzureMySQL
- Hostname: Your server's fully qualified domain name (FQDN)
- Port: 3306
- Username: Your admin username
- Password: Your admin password
- Click Test Connection to verify.
- Click OK to save the connection.
Important: Ensure that your client's IP address is allowed through the server's firewall rules in the Azure portal.
Using Command-Line Interface (CLI)
You can also connect using the MySQL command-line client:
mysql -h <your-server-name>.mysql.database.azure.com -u <your-admin-username> -p
You will be prompted to enter your password.
3. Create and Manage Databases
After connecting, you can create and manage your databases:
-- Create a new database
CREATE DATABASE myapp_db;
-- Select the database
USE myapp_db;
-- Create a table
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
price DECIMAL(10, 2)
);
-- Insert some data
INSERT INTO products (name, price) VALUES ('Gadget', 99.99);
INSERT INTO products (name, price) VALUES ('Widget', 19.50);
-- Query the data
SELECT * FROM products;
4. Configure Server Parameters
Azure Database for MySQL allows you to configure various server parameters to optimize performance and behavior. You can do this through the Azure portal:
- Navigate to your Azure Database for MySQL server in the Azure portal.
- Under Settings, select Server parameters.
- Here you can view and modify parameters like
max_connections
,innodb_buffer_pool_size
, and more.
Tip: Always review and understand the impact of changing server parameters before making modifications.
5. Secure Your Database
Security is paramount. Azure Database for MySQL offers robust security features:
- SSL/TLS Encryption: Enforce SSL connections to protect data in transit.
- Firewall Rules: Restrict access to your server by IP address.
- VNet Service Endpoints: Provide secure and direct connectivity from your Azure Virtual Network to your server.
- Azure Active Directory Authentication: Integrate with Azure AD for centralized identity and access management.
Next Steps
Congratulations! You've successfully set up and connected to your Azure Database for MySQL server.
- Explore advanced features like read replicas and automatic backups.
- Learn how to migrate your existing databases to Azure.
- Integrate your application with Azure Database for MySQL.
For more detailed information, refer to the Azure Database for MySQL Reference Guide.