Main Content

Access Relational Database Data in MATLAB

This tutorial shows how to use Database Toolbox™ with relational databases. To gain the maximum benefit from this toolbox and understand its capabilities, use the following steps and decision flow chart.

  1. If you do not have an installed database and want to store relational data quickly, use the MATLAB® interface to SQLite. For details, see Interact with Data in SQLite Database Using MATLAB Interface to SQLite.

  2. Install your database. For details, refer to your database administrator or your database documentation.

  3. Choose between using the Database Explorer app or the command line. For details, see Connection Options.

  4. If you have a MySQL® database, then you can use the MySQL native interface. For details, see MySQL Native Interface.

  5. If you have a PostgreSQL database, then you can use the PostgreSQL native interface. For details, see PostgreSQL Native Interface.

  6. Choose between using an ODBC driver or a JDBC driver. For details, see Choose Between ODBC and JDBC Drivers.

  7. If you are using a JDBC driver, you need to install the driver. An ODBC driver is typically preinstalled on your computer. For details about ODBC and JDBC drivers, see Driver Installation. If you have questions about which driver you need, refer to your database administrator or your database documentation.

  8. If you have a Linux® platform, then you can use the odbc function to create an ODBC database connection using a defined data source or a connection string. The connection string is a DSN-less connection. (DSN is a data source name.)

  9. Create a data source for an ODBC-compliant or JDBC-compliant driver. For details, see Configure Driver and Data Source.

  10. Test the connection to your database using the Database Explorer app or the command line.

  11. Connect to your database using the Database Explorer app or the command line. For details, see Connect to Database.

  12. Select data from your database and import the data into a MATLAB variable by using the Database Explorer app or the command line. For details, see Data Import Using Database Explorer App or Command Line.

  13. Insert data into your database by exporting data from a MATLAB variable. For details, see the sqlwrite function.

  14. When you use the Database Explorer app to import data, generate a MATLAB script to automate your tasks. For details, see Generate MATLAB Script.

This flow chart illustrates the steps to take and the decisions to make when you use Database Toolbox with relational databases.

Workflow for making a database connection and deciding to use the Database Explorer app or the command line

Related Topics