Main Content

MySQL ODBC for macOS

This tutorial shows how to set up a data source and connect to a MySQL® database using the MATLAB® command line on the Apple macOS platform. You can use the shipped MariaDB® ODBC driver or the downloaded MySQL ODBC driver.

MariaDB ODBC Shipped Driver

  1. To create a data source on your Mac computer using the MariaDB ODBC driver, you need the unixODBC driver manager. Verify the unixODBC driver manager is installed at /usr/local/Cellar/unixodbc. If you need install the unixODBC driver manager, you can download it from Homebrew: https://formulae.brew.sh/formula/unixodbc.

  2. Set up the data source by creating the file ~/.odbc.ini (if it does not exist) and by adding the data source information to the file. This example assumes that you are connecting to a database server dbtb04, the port number is 3306, toy_store is the database name, and MATLAB is installed at the location /Applications/MATLAB_R2023b.app.

    [mysql-server-shipped-driver]
    Description=Connect to MySQL server using shipped MariaDB ODBC driver
    Driver=/Applications/MATLAB_R2023b.app/bin/maci64/libmaodbc.dylib
    Server=dbtb04
    Port=3306
    Database=toy_store
  3. Use the command line to make the connection.

    conn = odbc("mysql-server-shipped-driver","root","matlab");

MySQL ODBC Downloaded Driver

  1. To verify that your computer has the ODBC driver, look for the libmyodbc8w.so driver in the folder /usr/local/mysql-connector-odbc-8.0.30-macos12-x86-64bit/lib/.

    You can download and install the MySQL driver from MySQL Downloads on the Oracle® website. To create a data source on your Mac computer using the MySQL ODBC driver, you need the iODBC driver manager. 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. Set up the data source by creating the file ~/.odbc.ini (if it does not exist) and by adding the data source information to the file. This example assumes that you are connecting to a database server dbtb04, the port number is 3306, toy_store is the database name, and Driver defines the ODBC driver location.

    [mysql-server]
    Description=Connect to MySQL server using MySQL ODBC driver 
    Driver=/usr/local/mysql-connector-odbc-8.0.30-macos12-x86-64bit/lib/libmyodbc8w.so
    Server=dbtb04
    Port=3306
    DATABASE=toy_store
  3. Use the command line to make the connection.

    conn = odbc("mysql-server","root","matlab","DriverManager","iODBC");

See Also

Functions

Related Topics