Main Content

Microsoft SQL Server ODBC for macOS

This tutorial shows how to set up a data source and connect to a Microsoft® SQL Server® database using the command line. The tutorial uses the Microsoft ODBC Driver 18.1 for Microsoft SQL Server to connect to a Microsoft SQL Server 2016 Express database on the Apple macOS platform.

Step 1. Verify the driver installation.

The ODBC driver is typically preinstalled on your computer. To verify that your computer has the driver, look for the libmsodbcsql.18.dylib driver in the folder /usr/local/Cellar/msodbcsql18/ If you need to install an ODBC driver, contact your database administrator or see Install the Microsoft ODBC Driver for SQL Server on the Microsoft website. For details about the driver installation or troubleshooting the installation, contact your database administrator or refer to your database documentation on ODBC drivers.

To create a data source on your Mac computer, you need the unixODBC driver manager. You can download and install the unixODBC driver manager from Homebrew:

Step 2. Set up the data source.

Set up the data source by creating the file ~/.odbc.ini (if it does not exist) and by adding the data source information. This example assumes that you are connecting to a database server dbtb12, the port number is 54317, and toy_store is the database name.

Description = Connect to Microsoft SQL server using Microsoft SQL server ODBC driver
Driver = /usr/local/Cellar/msodbcsql18/
Server = dbtb12,54317
Database = toy_store

Step 3. Connect using the command line.

MATLAB® supports the unixODBC driver manager through the entry-point functions database and odbc.

Use the command line to make the connection using either entry-point function.

conn = odbc("mssql-server-data-source","root","matlab");
conn = database("mssql-server-data-source","root","matlab");

See Also


Related Topics