Description

The MindsDB.Databases.createDatabase function connects a new data source to MindsDB.

Syntax

Here is how to connect our sample MySQL database:

const connectionParams = {
  'user': 'user',
  'port': 3306,
  'password': 'MindsDBUser123!',
  'host': 'samples.mindsdb.com',
  'database': 'public'
}

try {

  const mysqlDatabase = await MindsDB.Databases.createDatabase(
    'mysql_datasource',
    'mysql',
    connectionParams);
  console.log('connected a database');

} catch (error) {
  // Couldn't connect to database
  console.log(error);
}

First, we define the connection parameters and then use the createDatabase function to connect a database.