doctl-databases-db
Manage DigitalOcean database clusters
TLDR
Run a doctl databases db command with an access token
Retrieve the name of the given database hosted in the given database cluster
List existing databases hosted within a given database cluster
Create a database with the given name in the given database cluster
Delete the database with the given name in the given database cluster
SYNOPSIS
doctl databases db <command> <cluster-id> [flags]
Where <command> can be:
create
: Create a new database within the specified cluster.delete
: Delete an existing database from the specified cluster.get
: Retrieve details about a specific database within the specified cluster.
PARAMETERS
<cluster-id>
The unique identifier (UUID) of the DigitalOcean Managed Database Cluster. This is a required positional argument for all doctl databases db
subcommands.--database <name>
The name of the database to operate on (e.g., my_app_db
). This is a required flag for all create
, delete
, and get
subcommands.--encoding <encoding-type>
(Optional) Used with create
. Specifies the character encoding for the new database (e.g., UTF8
). Defaults to UTF8
.--user <username>
(Optional) Used with create
. The name of the database user who will own the new database. If not specified, the database is typically owned by the doadmin
user or the cluster's default owner.--password <password>
(Optional) Used with create
. The password for the user specified with --user
. Required if --user
is provided and the user does not exist.-f
, --force
(Optional) Used with delete
. Bypass the confirmation prompt when deleting a database, allowing for non-interactive deletion. Use with extreme caution.--output <format>
(Global doctl
flag) Adjusts the output format (e.g., json
, yaml
, text
). Affects all subcommands.--format <columns>
(Global doctl
flag) Specifies the columns to display in table output (e.g., ID,NAME,STATUS
). Affects all subcommands.
DESCRIPTION
The doctl databases db
command provides a powerful interface for interacting with and managing individual databases inside a DigitalOcean Managed Database Cluster. Unlike commands that manage the cluster itself (e.g., creating or deleting an entire cluster), this command focuses on the granular control of databases within an already provisioned cluster. It allows users to perform operations such as creating new databases, retrieving details about existing ones, and safely deleting them. This is crucial for application development and deployment, where distinct databases are often required for different services, environments, or tenants. The command facilitates automation of database provisioning and management tasks.
CAVEATS
- Prerequisites: This command requires an existing DigitalOcean Managed Database Cluster. It cannot create or manage standalone databases or databases on unmanaged servers.
- Irreversibility of Deletion: Deleting a database is an irreversible action. All data within that database will be permanently lost. Exercise extreme caution, especially when using the
--force
flag. - User Management: While
doctl databases db create
allows specifying an owner, full user and privilege management (creating users, granting/revoking permissions) is handled by thedoctl databases user
command. - Naming Conventions: Database names must adhere to the specific rules of the underlying database engine (e.g., PostgreSQL, MySQL).
AUTHENTICATION
Before using doctl databases db
, ensure doctl
is authenticated with your DigitalOcean account using doctl auth init
.
LISTING DATABASES
To see a list of databases within a cluster, you typically get the cluster details first, then parse the output, or use doctl databases get <cluster-id>
--output json
and look for the 'databases' array. There isn't a direct list
subcommand for individual databases under doctl databases db
.
EXAMPLE USAGE
1. Create a new database:doctl databases db create d3f0a5b8-c1d2-e3f4-a5b6-c7d8e9f0a1b2 --database my_new_app_db --user app_user --password 'StrongP@ssw0rd!'
2. Get details of a database:doctl databases db get d3f0a5b8-c1d2-e3f4-a5b6-c7d8e9f0a1b2 --database my_new_app_db --output json
3. Delete a database (with force):doctl databases db delete d3f0a5b8-c1d2-e3f4-a5b6-c7d8e9f0a1b2 --database my_old_data --force
HISTORY
The doctl
command-line interface was developed by DigitalOcean to provide programmatic access to its cloud services. As DigitalOcean expanded its offerings to include Managed Databases, the doctl databases
subcommand was introduced to manage these new services. The doctl databases db
set of commands represents a refinement of this functionality, allowing for more granular control over individual databases within a cluster, which became essential as customers adopted managed databases for complex applications requiring multiple isolated databases. Its development mirrors the increasing maturity and feature richness of DigitalOcean's database-as-a-service offering.
SEE ALSO
doctl databases: General commands for managing DigitalOcean Managed Database Clusters (e.g., creating, listing, deleting clusters)., doctl databases user: Manage users for DigitalOcean Managed Database Clusters (e.g., creating, deleting, listing users)., doctl databases connection: Get connection details for a database cluster., doctl auth init: Initialize and authenticate the doctl client with your DigitalOcean account.