Connect a Data Source
Description
MindsDB lets you connect to your favorite databases, data warehouses, data lakes, etc., via the CREATE DATABASE
command.
The MindsDB SQL API supports creating connections to integrations by passing the connection parameters specific per integration. You can find more in the Supported Integrations chapter.
MindsDB doesn’t store or copy your data. Instead, it fetches data directly from your connected sources each time you make a query, ensuring that any changes to the data are instantly reflected. This means your data remains in its original location, and MindsDB always works with the most up-to-date information.
Syntax
Let’s review the syntax for the CREATE DATABASE
command.
On execution, we get:
Where:
Name | Description |
---|---|
datasource_name | Identifier for the data source to be created. |
engine_name | Engine to be selected depending on the database connection. |
PARAMETERS | {"key": "value"} object with the connection parameters specific for each engine. |
SQL Commands Resulting in the Same Output Please note that the
keywords/statements enclosed within square brackets are optional. Also, by
default, the engine is mindsdb
if not provided otherwise. That yields the
following SQL commands to result in the same output.
What’s available on your installation
Here is how you can query for all the available data handlers used to create database connections.
Or, alternatively:
And here is how you can query for all the connected databases:
Or, alternatively:
Example
Connecting a Data Source
Here is an example of how to connect to a MySQL database.
On execution, we get:
Listing Linked Databases
You can list all the linked databases using the command below.
On execution, we get:
Making your Local Database Available to MindsDB
When connecting your local database to MindsDB Cloud, you should expose the local database server to be publicly accessible. It is easy to accomplish using Ngrok Tunnel. The free tier offers all you need to get started.
The installation instructions are easy to follow. Head over to the downloads page and choose your operating system. Follow the instructions for installation.
Then create a free account at Ngrok to get an auth token that you can use to configure your Ngrok instance.
Once installed and configured, run the following command to obtain the host and
port for your localhost at port-number
.
Here is an example. Assuming that you run a PostgreSQL database at
localhost:5432
, use the following command:
On execution, we get:
Now you can access your local database at 4.tcp.ngrok.io:15093
instead of
localhost:5432
.
So to connect your local database to the MindsDB GUI, use the Forwarding
information. The host is 4.tcp.ngrok.io
, and the port is 15093
.
Proceed to create a database connection in the MindsDB GUI by executing the
CREATE DATABASE
statement with the host and port number obtained from
Ngrok.
Please note that the Ngrok tunnel loses connection when stopped or canceled. To reconnect your local database to MindsDB, you should create an Ngrok tunnel again. In the free tier, Ngrok changes the host and port values each time you launch the program, so you need to reconnect your database in the MindsDB Cloud by passing the new host and port values obtained from Ngrok.
Before resetting the database connection, drop the previously connected data
source using the DROP DATABASE
statement.
After dropping the data source and reconnecting your local database, you can use
the predictors that you trained using the previously connected data source.
However, if you have to RETRAIN
your predictors, please ensure the database
connection has the same name you used when creating the predictor to avoid
failing to retrain.
Supported Integrations
The list of databases supported by MindsDB keeps growing. Check out all our database integrations here.
Was this page helpful?