How to use the command doctl databases (with examples)
The doctl databases
command is used to manage MySQL, Redis, PostgreSQL, and MongoDB database services on the DigitalOcean platform. With this command, you can perform various operations such as getting details for a database cluster, listing all your database clusters, creating a new database cluster, and deleting a cluster.
Use case 1: Run a doctl databases
command with an access token
Code:
doctl databases command --access-token access_token
Motivation: Using an access token allows you to authenticate and authorize your API requests without exposing your confidential login credentials. To run any doctl databases
command, you need to provide your access token to the --access-token
flag.
Explanation:
doctl databases command
is the base command to interact with database services.--access-token
is a flag used to specify the access token for authentication.
Example Output:
Successfully authenticated!
Use case 2: Get details for a database cluster
Code:
doctl databases get
Motivation: Getting details for a database cluster is useful for gaining information about the cluster, such as its name, engine, version, size, and region. This information can help you make informed decisions about managing your database clusters effectively.
Explanation:
doctl databases get
is the command to retrieve detailed information about a specific database cluster.
Example Output:
ID: 123456789
Name: my-database-cluster
Engine: postgresql
Version: 13
Region: nyc1
Size: db-s-1vcpu-2gb
Status: Available
...
Use case 3: List your database clusters
Code:
doctl databases list
Motivation: Listing all your database clusters helps you get an overview of the existing database infrastructure. It is particularly useful when you need to manage multiple clusters and want to quickly see their names, engines, sizes, and regions.
Explanation:
doctl databases list
is the command to retrieve a list of all your database clusters.
Example Output:
ID Name Engine Status Read Replicas Private Network Enabled Size Region
123456789 my-database-cluster postgres Available 0 true db-s-1vcpu-2gb nyc1
987654321 another-database mysql Available 1 false db-s-1vcpu-2gb sfo2
Use case 4: Create a database cluster
Code:
doctl databases create database_name
Motivation: Creating a new database cluster allows you to set up a dedicated environment for your database. You can specify a name for the cluster, choose the desired database engine (MySQL, Redis, PostgreSQL, or MongoDB), and configure other settings based on your requirements.
Explanation:
doctl databases create
is the command to create a new database cluster.database_name
is an argument specifying the name for the new cluster.
Example Output:
Creating database cluster... DONE
Database cluster ID: 987654321
Database cluster name: my-database-cluster
Status: Creating
...
Use case 5: Delete a cluster
Code:
doctl databases delete database_id
Motivation: Deleting a database cluster removes the entire cluster from your infrastructure. This is helpful when you want to clean up unused or unnecessary clusters to save costs and resources.
Explanation:
doctl databases delete
is the command to delete a database cluster.database_id
is an argument specifying the ID of the cluster to be deleted.
Example Output:
Deleting database cluster... DONE
Conclusion:
In this article, you learned how to use the doctl databases
command to manage your database services on DigitalOcean. With the provided examples, you can now execute various operations such as getting cluster details, listing all clusters, creating a new cluster, and deleting a cluster.