connect to database
to connect to a database from matlab®, install an odbc or jdbc driver and create a data source. or, you can connect to mysql® or postgresql databases using the native interfaces. for details about driver installation and data source setup, see . if you do not have an installed database and want to store relational data quickly, you can use the matlab interface to sqlite. for details, see .
you can connect to a database using the database explorer app or the command line. these two options enable you to perform different actions. for details about deciding which option to use, see .
database explorer app connection workflow
use these steps as a general workflow for creating a database connection using the app.
in the data source section of the database explorer tab, click configure data source and select the appropriate option for configuring an odbc, jdbc, or native data source.
in the connections section, click connect and select the configured data source to create a database connection.
to close the database connection, in the connections section, click close connection. if multiple connections are open, close the database connection of your choice by selecting the corresponding data source from the close connection list.
command line connection workflow
use these steps as a general workflow for creating a database connection at the command line.
configure an odbc data source using the function, or configure a jdbc data source using the function.
create a database connection by completing one of these steps:
create an odbc database connection using the function.
create an odbc or jdbc database connection using the function.
create a mysql database connection using the mysql native interface with the function.
create a postgresql database connection using the postgresql native interface with the function.
if you do not configure a data source using a data source name (dsn), you can create a dsn-less connection using a connection string with the function.
close the database connection using the function.
database list
after choosing to use the database explorer app or the command line, connect to your database by following the steps for the corresponding database and driver type, as given in this table.
database | driver or interface | connection topics |
---|---|---|
microsoft access® | odbc | |
microsoft® sql server® | odbc | |
jdbc | ||
oracle® | odbc | |
jdbc | ||
mysql | odbc | |
mysql native interface | ||
jdbc | ||
postgresql | odbc | |
postgresql native interface | ||
jdbc | ||
sqlite | jdbc | |
none | to create an sqlite connection when no driver or database installation is required, use the function to create a new sqlite database file or connect to an existing sqlite database file. | |
all other odbc-compliant or jdbc-compliant databases | odbc or jdbc |
see also
| | | |