Connect a database
Connect PostgreSQL, MySQL and other sources, store credentials as secrets and query tables read-only.
Instead of uploading files, you can connect mlflow to a database and use a table or a query as a data source. The data stays in your database. mlflow reads it to profile it and to snapshot it when you train.
Two things make this possible:
- A connection holds where the database is (host, port, database, user) and a link to a credential.
- A secret holds the password or key, encrypted. The connection refers to it, so the password is never copied into the connection or into a data source.
Supported sources
| Source | Maturity |
|---|---|
| PostgreSQL | Stable |
| MySQL | Stable |
| Amazon Redshift | Experimental |
| SQL Server | Experimental |
| Oracle | Experimental |
| Snowflake | Experimental |
| BigQuery | Experimental |
| HTTP JSON API | Experimental |
Stable means the connector is tested against a real database. Experimental connectors are built against the vendor's documented interface but are not yet verified against the real service. The app shows an Experimental badge next to them. Try them on non-critical data first.
An HTTP JSON API connection reads records from a URL (you give the URL and a Records path, for example data.items). It reads tables, not SQL queries.
Create a connection
You can create a connection in two places: from the Add data dialog while you add data, or in the workspace settings.
From the Add data dialog
Open the database tab
On the Data page, select Add data and choose the Connect a database tab.
Choose a connector
Under Connector, pick the source type. If the workspace already has connections of that type, pick one under Connection, or choose Create a new connection.
Fill in the connection details
Give the connection a Connection name, for example prod-warehouse. Then fill in the fields for the connector. For PostgreSQL and MySQL these are Host, Port, Database and User (PostgreSQL also has Schema (default: public)), plus the Password. For BigQuery you give the Project ID, the Dataset and a Service-account key (JSON). Leave the key empty to use the server's own Google credentials.
The password is saved as an encrypted workspace secret and is never shown again.
Test the connection
Select Test connection. You see Connection works or Connection failed with a reason. See Test results.
From the workspace settings
In the sidebar select Settings, then open the Connections & secrets section. The list shows each connection with its status (ok or error) and the time of the last test. Select New connection, enter a Name and a Kind, and fill in the details. Use Test to check a connection and Delete to remove it.
If you delete a connection, the data sources that use it stay in the list, but they cannot read data until you create a new connection for them.
Secrets
Secrets are credentials that connections and other features use: database passwords, API keys, service-account keys. They live in the same Connections & secrets section of the workspace settings, under Secrets.
- Select New secret. Enter a Name, choose the Kind (Opaque (generic), Database password, API key, Git PAT or S3 secret key) and enter the Value.
- mlflow stores the value encrypted. After you save it, the value is never shown again; the list shows only the last four characters.
- A secret can be used only inside its own workspace. Only a workspace admin or the person who created the secret can attach it to a connection.
- In a connection form, Use a saved secret lets you pick an existing secret instead of typing a password.
Deleting a secret cannot be undone
Connections that use a deleted secret stop working. Create a new secret and attach it to the connection.
Query a table
After a connection passes its test, use it to create a data source.
Choose what to import
In the Add data dialog, under the connection, choose the import mode: Table or SQL query. For Table, mlflow lists the tables of the database (Listing tables...) and you pick one under Pick a table. If the list is empty you see No tables found.
You can also select Browse tables on a connection in the settings and then Register as DataSource.
Or write a query
Choose SQL query and write a single SELECT statement, for example SELECT * FROM orders WHERE created_at > '2025-01-01'. Use a query to filter rows, join tables or choose columns before the data reaches mlflow.
Preview
Select Preview rows to see the first rows. The preview shows how many rows were returned and how many are shown.
Name and add
Enter a Data source name and select Add data source. The new data source appears on the Data page like any other.
To get newer data later, open Versions on the data source and select Refresh now. This runs the table read or the query again and saves a new version, so runs keep a record of exactly which data they used.
Limits
- Read-only queries only. A query must be one
SELECTstatement. mlflow rejects statements that change data or the database (INSERT,UPDATE,DELETE,DROP,CREATE,COPYand similar), more than one statement, SQL comments, and a few other constructs. The query runs inside a read-only, time-limited transaction that is always rolled back. Queries are limited to 20,000 characters. - Row limit. A query-based data source can return up to 1,000,000 rows when it is snapshotted by default. A larger result fails with a message that names the limit. The operator of a self-hosted server can change it.
- Time limit. A query is stopped after 120 seconds by default.
- Output columns. Give every output column a unique name. For example, when you join two tables that both have an
idcolumn, rename one withAS. - Roles. To test a connection, list tables, preview or run a query, you need a workspace role that can write. Viewers and service accounts are read-only and cannot.
Use a read-only login
For SQL Server, Snowflake, BigQuery and Oracle, the database cannot be forced into a read-only session. Create a database user or role that can only read, and use its credentials. The connection form reminds you of this. It is good practice for every database.
Network access
mlflow connects to your database from the server, not from your browser. The server must be able to reach the host and port.
- Public hosts are allowed.
- Private addresses (a database on the same machine or on an internal network) are blocked by default. On a self-hosted installation, an administrator can allow them. See Configuration.
- Link-local and cloud metadata addresses are always blocked.
The host name is checked every time mlflow connects, to protect your network from being reached through a data source.
Test results
If a test fails, the message points to the cause:
| Message | What to check |
|---|---|
| Authentication failed | The user name, and the password or key |
| Could not reach the database server | The host and port, and that mlflow is allowed to connect to that address |
| The connection timed out | The host, the port, and any firewall between mlflow and the database |
| The database was not found | The database name |
| Signed in, but this user is not allowed to use the database | The user's permissions |
Next steps
Learn the theory
Lessons on learning.mlflow.es that explain the ideas behind this page.
Updated 2026-11-22