Doctl / Create Database User
Create Database User
Create a database user in DigitalOcean's Databases service.
doctl databases user create <database_id> <user_name> doctl databases user create <database_id> <user_name> #!/bin/bash
# Create Database User
doctl databases user create {{database_id}} {{user_name}} import subprocess
# Create Database User
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"doctl",
"databases",
"user",
"create",
"<database_id>",
"<user_name>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: doctl not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
When provisioning a new database user to limit access for security purposes.
Pro Tip
Use the `--no-wait` flag to return immediately without waiting for the request to complete, which can optimize long scripts.
Command Builder
Tune the command before you copy it
doctl databases user create <database_id> <user_name> Terminal Output
Expected runtime feedback
Creating database user...
User Details:
+----------------+------------------+
| User Name | Status |
+----------------+------------------+
| new_user | Created |
+----------------+------------------+
Database ID: db-123456
User ID: user-789012 Anatomy of Output
Understanding the result
User created with ID: user_123456 User ID Identifier of the newly created user.
Username: user_name Username The username provided during creation.
Status: active User Status Current status of the database user.
Troubleshooting
Common pitfalls
Error creating user: Database not found.
Solution: Verify the database_id is correct.
Error: User already exists.
Solution: Choose a different username.
Error: Permission denied to create user.
Solution: Check permissions of the access token used.
Command Breakdown
What each part is doing
-
doctl - Base Command
- The executable that performs this operation. Here it runs Doctl before the shell applies any redirect operators.
-
<database_id> - database id
- The value supplied for database id.
-
<user_name> - user name
- The user value supplied to this command.
How To Run
Execution path
- Step 1
Run `doctl databases user create db-123456 new_user` to create the user.
- Step 2
Verify user creation with `doctl databases user list db-123456`.
Alternative Approaches
Comparable commands in other tools
Alternative documentation tools for the same job.