Use a local database as a source or destination
If you want to use a database running in your local environment as a data source or destination for synthetic data, you can use ngrok to expose the local database for external connections over the Internet and then add the ngrok forwarding address and port in a new MOSTLY AI connector.
Install ngrok
ngrok makes it possible to expose a locally running server to the Internet. To do so, you need an ngrok account and an ngrok authentication token.
Steps
- Create an
ngrokaccount. - Install
ngrok. - Copy your authentication token.
- Add the authentication token to your local environment.
ngrok config add-authtoken TOKEN
Result
ngrok can now use the token to connect to your account.
Run a local database
With Docker Compose, you can quickly run a database locally as a Docker container just by defining a new service in a YAML file.
The steps below show how to run a PostgreSQL database.
Steps
-
Create a new YAML file with the name
mostly-ai-postgresql-compose.yamland paste the contents below.mostly-ai-postgresql-compose.yamlversion: '3.7' services: mostly_ai_sd_db: image: postgres environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: changeme POSTGRES_DB: my_synthetic_db ports: - '5432:5432' volumes: - mostly_ai_sd_db:/var/lib/postgresql/data volumes: mostly_ai_sd_db: -
Set the credentials and database name in the lines highlighted below.
mostly-ai-postgresql-compose.yaml--- POSTGRES_USER: postgres POSTGRES_PASSWORD: changeme POSTGRES_DB: my_synthetic_db -
Run
docker composeto start the service defined in the YAML file.docker compose -f ./mostly-ai-postgresql-compose.yaml logs
Result
The PostgreSQL database is now running locally.
Expose your database with ngrok
To expose your database from your local environment, you need to know the port at which the database service is listening. Check your database configuration for that. For example, the default port for PostgreSQL is 5432, for MySQL - 3306.
Steps
- Run
ngrokto expose your database port.Step result:ngrok tcp PORTngrokrandomly assigns a hostname and a forwarding port for your database. - Copy the forwarding address that is listed in the
ngrokcommand status.
Create a connector
You can use your local database as a data source, data destination, or both. In either case, you need a separate connector (a source or a destination) in MOSTLY AI.
Steps
- From the Connectors page, select the type of connector you want to create from the available sources.
- Provide the connector details.
- For Access type, select Source or Destination.
- For Host, paste the
ngrokforwarding address. - For Port, paste the
ngrokforwarding port number.💡You can find the forwarding address and port in the output of thengrokcommand from Expose your database withngrok. - For Username, Password, and Database, set the database credentials and the database name.
💡If you plan to use the same database as a source and destination, create a separate database for the destination connector to prevent potential loss of original data.
- Click Save.
What’s next
To use the local database as a source, see Use as a data source.
To use the local database as a destination, see Use as a data destination.