You can connect to a database in various ways using Database Toolbox™. If you have access to a database, create a data source. Then, you can connect to the database either by using the Database Explorer app or the command line. 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 Interact with Data in SQLite Database Using MATLAB Interface to SQLite.
Creating or Connecting to Data Source
If you already have a database driver installed, you can create a data source.
For an ODBC driver, open the Microsoft® ODBC Data Source Administrator dialog box by using the
configureODBCDataSourcefunction or the Database Explorer app.
For a JDBC driver, open the JDBC Data Source Configuration dialog box by using the Database Explorer app, or configure a JDBC data source by using the
databaseConnectionOptionsfunction at the command line.
For examples, see Configure Driver and Data Source. Otherwise, see Driver Installation for information about installing your driver. For configuring MySQL® or PostgreSQL native interfaces, see MySQL Native Interface or PostgreSQL Native Interface.
If your data source is already defined, then you are ready to connect to your
database. If you do not define a data source, you can connect to your database using
a DSN-less connection string with the
function. (DSN is a data source name.) For details, see Connect to Database.
After establishing a connection, you can explore the database and view data using the Database Explorer app or the command line. For details, see Data Import Using Database Explorer App or Command Line.
Defining Operating System Authentication
Operating system authentication enables you to connect to a database using your operating system user account. The operating system performs user validation, and the database does not require a different user name and password. Operating system authentication facilitates the maintenance of database access credentials. For example, Windows® provides operating system authentication that can be configured to work with a Microsoft SQL Server® database. For details about Microsoft SQL Server Windows authentication, see Set up the operating system authentication.
Use this table to choose your best connection option.
Database Explorer app
Several options enable you to connect to your database at the command line. Use this table to choose your best command line connection option.
Command Line Connection Option
Connect to your database with maximum performance.
Connect to your database by using a connection string.
For details, see the
Native interface connection
Connect to MySQL and PostgreSQL databases. For PostgreSQL databases, you can connect without the installation of a driver. For details, see MySQL Native Interface and PostgreSQL Native Interface.
Achieve maximum platform independence.
Import data without installing a database or driver. For details, see Interact with Data in SQLite Database Using MATLAB Interface to SQLite.
You can create multiple connections at a time to the same database or different
databases. For creating multiple connections using the Database Explorer app, see
Create SQL Queries Using Database Explorer App. Or, you can
database function to create multiple
connections at the command line.