0%
Azure CLI Commands for Databases

Azure CLI Commands for Databases

Discover the Azure CLI commands for managing databases on Azure.

I

InSkillCoach

· min

Azure CLI Commands for Databases

Discover the essential commands for managing databases on Azure.

Azure SQL Database

Creating a SQL Database

# Create a SQL server
az sql server create \
    --name mon-serveur \
    --resource-group mon-groupe \
    --location westeurope \
    --admin-user adminuser \
    --admin-password MonMotDePasse123!

# Create a database
az sql db create \
    --resource-group mon-groupe \
    --server mon-serveur \
    --name ma-base \
    --edition Standard \
    --capacity 10

Managing the Database

# Configure the firewall
az sql server firewall-rule create \
    --resource-group mon-groupe \
    --server mon-serveur \
    --name ma-regle \
    --start-ip-address 0.0.0.0 \
    --end-ip-address 255.255.255.255

# Scale up
az sql db update \
    --resource-group mon-groupe \
    --server mon-serveur \
    --name ma-base \
    --capacity 20

Azure Database for PostgreSQL

Creating a PostgreSQL Database

# Create a PostgreSQL server
az postgres flexible-server create \
    --name mon-serveur \
    --resource-group mon-groupe \
    --location westeurope \
    --admin-user adminuser \
    --admin-password MonMotDePasse123! \
    --sku-name Standard_B1ms

# Create a database
az postgres flexible-server db create \
    --resource-group mon-groupe \
    --server-name mon-serveur \
    --database-name ma-base

Managing the Database

# Configure the firewall
az postgres flexible-server firewall-rule create \
    --resource-group mon-groupe \
    --name mon-serveur \
    --rule-name ma-regle \
    --start-ip-address 0.0.0.0 \
    --end-ip-address 255.255.255.255

# Scale up
az postgres flexible-server update \
    --name mon-serveur \
    --resource-group mon-groupe \
    --sku-name Standard_B2ms

Azure Cosmos DB

Creating a Cosmos DB Database

# Create a Cosmos DB account
az cosmosdb create \
    --name mon-compte \
    --resource-group mon-groupe \
    --kind GlobalDocumentDB \
    --default-consistency-level Session

# Create a database
az cosmosdb sql database create \
    --account-name mon-compte \
    --resource-group mon-groupe \
    --name ma-base

Managing Containers

# Create a container
az cosmosdb sql container create \
    --account-name mon-compte \
    --resource-group mon-groupe \
    --database-name ma-base \
    --name mon-conteneur \
    --partition-key-path "/id"

# Configure the TTL policy
az cosmosdb sql container update \
    --account-name mon-compte \
    --resource-group mon-groupe \
    --database-name ma-base \
    --name mon-conteneur \
    --ttl 3600

Azure Database for MySQL

Creating a MySQL Database

# Create a MySQL server
az mysql flexible-server create \
    --name mon-serveur \
    --resource-group mon-groupe \
    --location westeurope \
    --admin-user adminuser \
    --admin-password MonMotDePasse123! \
    --sku-name Standard_B1ms

# Create a database
az mysql flexible-server db create \
    --resource-group mon-groupe \
    --server-name mon-serveur \
    --database-name ma-base

Managing the Database

# Configure the firewall
az mysql flexible-server firewall-rule create \
    --resource-group mon-groupe \
    --name mon-serveur \
    --rule-name ma-regle \
    --start-ip-address 0.0.0.0 \
    --end-ip-address 255.255.255.255

# Scale up
az mysql flexible-server update \
    --name mon-serveur \
    --resource-group mon-groupe \
    --sku-name Standard_B2ms

Azure Cache for Redis

Creating a Redis Cache

# Create a Redis cache
az redis create \
    --name mon-cache \
    --resource-group mon-groupe \
    --location westeurope \
    --sku Basic \
    --vm-size C0

# Get the connection information
az redis list-keys \
    --name mon-cache \
    --resource-group mon-groupe

Managing the Cache

# Reboot the cache
az redis force-reboot \
    --name mon-cache \
    --resource-group mon-groupe \
    --reboot-type AllNodes

# Update the configuration
az redis update \
    --name mon-cache \
    --resource-group mon-groupe \
    --enable-non-ssl-port true

Best Practices

  1. Security

    • Use strong passwords
    • Configure the firewall
    • Enable encryption
    • Restrict access
  2. Performance

    • Choose the right size
    • Optimize queries
    • Use indexes
    • Monitor metrics
  3. Costs

    • Use reservations
    • Optimize resources
    • Clean up data
    • Monitor usage

Conclusion

Key takeaways:

  • Managing SQL databases
  • NoSQL databases with Cosmos DB
  • Relational databases
  • Redis cache

Recommendations:

  • Choose the right type of database
  • Secure access
  • Optimize performance
  • Follow best practices
  • Train on Microsoft Learn
InSkillCoach

About InSkillCoach

Training and technology expert

Coach specializing in advanced technologies and AI, backed by GNeurone Inc.

Certifications:

  • AWS Certified Solutions Architect – Professional
  • Google Cloud certifications
  • Microsoft Certified: DevOps Engineer Expert
  • Certified Kubernetes Administrator (CKA)
  • CompTIA Security+
963
88

Comments

Comments are powered by GitHub Discussions

Sign in with GitHub to join the discussion

Link copied!