Navigate databases like a filesystem. Build queries interactively. Keep your context.
Browse databases and tables without typing repetitive SQL:
[dbh]> /databases # List and select database
[dbh:sakila]> /tables # List and select table
[dbh:sakila:film]> /sample # See sample data immediatelyConstruct SELECT queries step-by-step:
[dbh:sakila:film]> /columns title,release_year,rating
[dbh:sakila:film]> /where rating='PG'
[dbh:sakila:film]> /order release_year
[dbh:sakila:film]> /desc
[dbh:sakila:film]> /limit 20
[dbh:sakila:film]> /selectExamine table structures, indexes, and relationships:
[dbh:sakila:film]> /describe # Column types and constraints
[dbh:sakila:film]> /indexes # All indexes on table
[dbh:sakila:film]> /foreign-keys # FK relationships
[dbh:sakila]> /schema # Full database schema with relationshipsExport query results to CSV, JSON, or SQL:
[dbh:sakila:film]> /export films.csv
[dbh:sakila:film]> /export --format json films.json
[dbh:sakila:film]> /backup film_backup.sqlMonitor processes and check privileges:
[dbh]> /whoami # Current user and privileges
[dbh]> /processes # Active MySQL processes
[dbh]> /users # All MySQL users
[dbh]> /variables # System variablesRun shell commands without losing your database context:
[dbh:sakila:film]> !ls -la # Single command
[dbh:sakila:film]> ! # Interactive shell, exit returns to dbh
[dbh:sakila:film]> !5 # Recall history command #5# Install
curl -o dbh https://raw.githubusercontent.com/Open-Technology-Foundation/dbh/main/dbh
chmod +x dbh
# Create MySQL credentials file
cat > ~/.mylocalhost.cnf << 'EOF'
[client]
host=localhost
user=your_username
password=your_password
EOF
chmod 600 ~/.mylocalhost.cnf
# Connect and explore
./dbh sakila
/tables
/table film
/sample 5- Bash 5.0+ (4.0+ with reduced functionality)
- MySQL client (
mysqlcommand in PATH) - MySQL server (local or remote)
lesspager (optional, for wide results)
Option A: Direct download
curl -o dbh https://raw.githubusercontent.com/Open-Technology-Foundation/dbh/main/dbh
chmod +x dbh
sudo mv dbh /usr/local/bin/ # Optional: make available system-wideOption B: Clone repository
git clone https://github.com/Open-Technology-Foundation/dbh.git
cd dbh
chmod +x dbhCreate a MySQL config file (keeps credentials out of command line):
# ~/.mylocalhost.cnf
[client]
host=localhost
user=your_username
password=your_passwordSet permissions: chmod 600 ~/.mylocalhost.cnf
Use different profiles for different servers:
dbh -p ~/.myremoteserver.cnf production_db| Prefix | Type | Example | Description |
|---|---|---|---|
/ |
Slash command | /tables |
Database operations |
! |
Bang command | !ls -la |
Shell commands |
| (none) | Direct SQL | SELECT * FROM users |
Execute SQL directly |
!N |
History recall | !5 |
Re-run command #5 |
The prompt shows your current selection:
[dbh]- No database selected[dbh:mysql]- Database "mysql" selected[dbh:sakila:film]- Database and table selected
| Category | Key Commands | Description |
|---|---|---|
| Navigation | /databases, /tables, /.. |
Browse and select databases/tables |
| Query Building | /columns, /where, /order, /select |
Build SELECT queries interactively |
| Table Info | /describe, /indexes, /foreign-keys, /find |
Examine table structure |
| Database Info | /schema, /charset, /engines |
Database-level information |
| Export | /export, /backup |
Export data to CSV/JSON/SQL |
| Admin | /whoami, /users, /processes, /variables |
Server administration |
| History | /history, !N, arrow keys |
Command history access |
| Config | /config show, /config edit |
Configuration management |
| Utility | /help, /state, /count, /sample |
General utilities |
For the complete command reference with examples, see USAGE.md.
Configuration file: ~/.config/dbh/config
# Default MySQL configuration file
DEFAULT_PROFILE=~/.mylocalhost.cnf
# Default database on startup (optional)
# DEFAULT_DATABASE=mysql
# Default LIMIT for SELECT queries
DEFAULT_LIMIT=100
# Maximum history entries
MAX_HISTORY=1000
# Pager program (optional)
# PAGER=less -SManage configuration within dbh:
/config show # Display current settings
/config create # Create default config file
/config edit # Open in editor
/config reload # Reload after manual changes- SQL Injection Prevention - User inputs are escaped using
quote_ident()andescape_sql_value() - Credential Security - Uses MySQL config files, never command-line passwords
- Secure Temp Files - Created with 0600 permissions, cleaned up on exit
- Error Handling - Errors reported without exposing sensitive information
dbh v3.7.1 - Interactive MySQL client with slash commands, shell access, and direct SQL
Usage:
dbh [Options] [database [table [command]]]
Options:
-p, --profile PROFILE MySQL config file (Default: ~/.mylocalhost.cnf)
-v, --verbose Increase verbosity
-q, --quiet Suppress non-error messages
-V, --version Print version and exit
-h, --help Display this help
| Document | Description |
|---|---|
| USAGE.md | Complete command reference with detailed examples |
| DEVELOPMENT.md | Contributing guidelines and architecture |
GNU General Public License v3.0 (GPL-3.0)
See LICENSE for the full text.
- Issues: GitHub Issues
- Repository: github.com/Open-Technology-Foundation/dbh
- Contributions: See DEVELOPMENT.md for guidelines