docs/integrations/data-integrations/ibm-db2.mdx
This documentation describes the integration of MindsDB with IBM Db2, the cloud-native database built to power low-latency transactions, real-time analytics and AI applications at scale. The integration allows MindsDB to access data stored in the IBM Db2 database and enhance it with AI capabilities.
Before proceeding, ensure the following prerequisites are met:
Establish a connection to your IBM Db2 database from MindsDB by executing the following SQL command:
CREATE DATABASE db2_datasource
WITH
engine = 'db2',
parameters = {
"host": "127.0.0.1",
"user": "db2inst1",
"password": "password",
"database": "example_db"
};
Required connection parameters include the following:
host: The hostname, IP address, or URL of the IBM Db2 database.user: The username for the IBM Db2 database.password: The password for the IBM Db2 database.database: The name of the IBM Db2 database to connect to.Optional connection parameters include the following:
port: The port number for connecting to the IBM Db2 database. Default is 50000.schema: The database schema to use within the IBM Db2 database.Retrieve data from a specified table by providing the integration name, schema, and table name:
SELECT *
FROM db2_datasource.schema_name.table_name
LIMIT 10;
Run IBM Db2 native queries directly on the connected database:
SELECT * FROM db2_datasource (
--Native Query Goes Here
WITH
DINFO (DEPTNO, AVGSALARY, EMPCOUNT) AS
(SELECT OTHERS.WORKDEPT, AVG(OTHERS.SALARY), COUNT(*)
FROM EMPLOYEE OTHERS
GROUP BY OTHERS.WORKDEPT
),
DINFOMAX AS
(SELECT MAX(AVGSALARY) AS AVGMAX FROM DINFO)
SELECT THIS_EMP.EMPNO, THIS_EMP.SALARY,
DINFO.AVGSALARY, DINFO.EMPCOUNT, DINFOMAX.AVGMAX
FROM EMPLOYEE THIS_EMP, DINFO, DINFOMAX
WHERE THIS_EMP.JOB = 'SALESREP'
AND THIS_EMP.WORKDEPT = DINFO.DEPTNO
);
This guide of common connection Db2 connection issues provided by IBM might also be helpful.