---
name: "Catmandu::Importer::DBI"
section: "3pm"
platform: "linux"
package: "libcatmandu-dbi-perl"
version: "0.13-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Catmandu::Importer::DBI"
---

# Catmandu::Importer::DBI(3pm)

Catmandu module to import data from any DBI source

## NAME

Catmandu::Importer::DBI - Catmandu module to import data from any DBI source

## LIMITATIONS

Text columns are assumed to be utf-8.

## SYNOPSIS

```
 # From the command line
 $ catmandu convert DBI --dsn dbi:mysql:foobar --user foo --password bar --query "select * from table"
 # From Perl code
 use Catmandu;
 my %attrs = (
        dsn => 'dbi:mysql:foobar' ,
        user => 'foo' ,
        password => 'bar' ,
        query => 'select * from table'
 );
 my $importer = Catmandu->importer('DBI',%attrs);
 # Optional set extra parameters on the database handle
 # $importer->dbh->{LongReadLen} = 1024 * 64;
 $importer->each(sub {
        my $row_hash = shift;
        ...
 });
```

## DESCRIPTION

This Catmandu::Importer can be used to access data stored in a relational database. Given a database handle and a SQL query an export of hits will be exported.

## CONFIGURATION

- dsn

  Required. The connection parameters to the database. See DBI for more information.

  Examples:

  ```
        dbi:mysql:foobar   <= a local mysql database 'foobar'
        dbi:Pg:dbname=foobar;host=myserver.org;port=5432 <= a remote PostGres database
        dbi:SQLite:mydb.sqlite <= a local SQLLite file based database mydb.sqlite
        dbi:Oracle:host=myserver.org;sid=data01 <= a remote Oracle database
  ```

  Drivers for each database need to be available on your computer. Install then with:

  ```
      cpanm DBD::mysql
      cpanm DBD::Pg
      cpanm DBD::SQLite
      cpanm DBD::Oracle
  ```

- user

  Optional. A user name to connect to the database

- password

  Optional. A password for connecting to the database

- query

  Required. An SQL query to be executed against the datbase.

## SEE ALSO

Catmandu, Catmandu::Importer , Catmandu::Store::DBI
