Main Content

MySQL ODBC for macOS DSN-Less Connection

This tutorial shows how to verify your driver installation on an Apple macOS platform and connect to an Oracle® MySQL® database using a connection string at the MATLAB® command line. A DSN-less connection string enables you to make a connection to the database without specifying a data source name (DSN). For this type of connection, you can use the MariaDB® OBDC driver that comes with MATLAB or the MySQL ODBC driver that you download.

MariaDB ODBC Shipped Driver

To make a DSN-less connection, enter the following code at the command line. This example assumes that you are connecting to a database server dbtb04, the port number is 3306, toy_store is the database name, and driverLocation is the ODBC driver location.

driverLocation = fullfile(matlabroot,"bin","maci64","libmaodbc.dylib")
dsnless = strcat("Driver=",driverLocation,";Server=dbtb04;Port=3306;UID=username;PWD=password;Database=toy_store")
conn = odbc(dsnless)

MySQL ODBC Downloaded Driver

  1. Download and install the MySQL ODBC driver from MySQL Community Downloads on the Oracle website. Verify the iODBC driver manager is installed at /usr/local/iODBC. If you need to install the iODBC driver manager, you can download it from the iodbc.org website.

  2. Connect to the database using the DSN-less connection string and the driver with the odbc function. This example assumes that you are connecting to a database server dbtb04, the port number is 3306, toy_store is the database name, username is the user name, and password is the password.

    dsnless = "Driver=/usr/local/mysql-connector-odbc-8.0.30-macos12-x86-64bit/lib/libmyodbc8w.so;Server=dbtb04;Port=3306;UID=username;PWD=password;Database=toy_store"
    conn = odbc(dsnless,"DriverManager","iODBC")

See Also

Functions

Related Topics