This add-on allows you to import a remote MySQL database into your local DDEV database. It supports direct connections as well as SSH tunneling for secure access to remote databases.
ddev add-on get esign/ddev-import-remote-db
ddev restart
After installation, make sure to commit the .ddev
directory to version control.
ddev import-remote-db --host <host> --user <user> --database <database> [--port <port>] [--ssh-host <ssh_host>] [--ssh-user <ssh_user>] [--password <password>]
Flags:
Flag | Description | Required |
---|---|---|
--host |
Remote MySQL host | Yes |
--user |
MySQL username | Yes |
--database |
Database name | Yes |
--port |
MySQL port (default: 3306) | No |
--ssh-host |
SSH host for tunneling | No |
--ssh-user |
SSH username | No |
--password |
MySQL password | No (will prompt if not provided) |
Example:
ddev import-remote-db --host db.example.com --user dbuser --database dbname --port 3307 --ssh-host ssh.example.com --ssh-user remoteuser --password mypass
ddev import-remote-db-1pw <1pw-item-uuid>
This command uses the 1Password CLI to securely fetch database credentials from your 1Password vault.
Steps:
- You will be prompted for the 1Password item UUID (or you can pass it as an argument).
- The script will fetch the database credentials and (optionally) SSH details from the 1Password item.
- You will be asked if SSH is required. If so, you can provide SSH host/user if not present in the item.
- The script will run
ddev import-remote-db
with the fetched credentials.
1Password Item Fields:
The script will look for the following fields in your 1Password item (it tries multiple field names for flexibility):
Purpose | Field Names (tries in order) | Required |
---|---|---|
Database Host | host , server , DB_HOST |
Yes |
Database Username | username , DB_USERNAME |
Yes |
Database Password | password , DB_PASSWORD |
Yes |
Database Name | database , DB_DATABASE |
Yes |
SSH Host | SSH_HOST |
No (prompted if SSH required) |
SSH Username | SSH_USER |
No (prompted if SSH required) |
Example:
ddev import-remote-db-1pw 0198f64f-5ac6-79a5-8238-750890b87ce5
Note: The 1Password CLI (op
) must be installed and you must be signed in. The script will check for this and prompt you if not.
Command | Description |
---|---|
ddev import-remote-db |
Import a remote MySQL database using direct or SSH connection |
ddev import-remote-db-1pw |
Import a remote MySQL database using credentials from 1Password |
ddev describe |
View service status and used ports for Import Remote Db |
ddev logs -s import-remote-db |
Check Import Remote Db logs |
To change the Docker image:
ddev dotenv set .ddev/.env.import-remote-db --import-remote-db-docker-image="ddev/ddev-utilities:latest"
ddev add-on get esign/ddev-import-remote-db
ddev restart
Make sure to commit the .ddev/.env.import-remote-db
file to version control.
All customization options (use with caution):
Variable | Flag | Default |
---|---|---|
IMPORT_REMOTE_DB_DOCKER_IMAGE |
--import-remote-db-docker-image |
ddev/ddev-utilities:latest |
Contributed and maintained by @esign