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.
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.
Install your database. For details, refer to your database administrator or your database documentation.
Choose between using the Database Explorer app or the command line. For details, see Connection Options.
If you have a MySQL® database, then you can use the MySQL native interface. For details, see MySQL Native Interface.
If you have a PostgreSQL database, then you can use the PostgreSQL native interface. For details, see PostgreSQL Native Interface.
Choose between using an ODBC driver or a JDBC driver. For details, see Choose Between ODBC and JDBC Drivers.
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.
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.)Create a data source for an ODBC-compliant or JDBC-compliant driver. For details, see Configure Driver and Data Source.
Test the connection to your database using the Database Explorer app or the command line.
Connect to your database using the Database Explorer app or the command line. For details, see Connect to Database.
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.
Insert data into your database by exporting data from a MATLAB variable. For details, see the
sqlwrite
function.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.
Related Topics
- Setup Requirements for Database Connection
- Choose Between ODBC and JDBC Drivers
- Configure Driver and Data Source
- Connect to Database
- Create SQL Queries Using Database Explorer App
- Join Tables Using Database Explorer App
- Data Preview Using Database Explorer App
- Interact with Data in SQLite Database Using MATLAB Interface to SQLite