Informations Technologie (IT)

Using ODBC driver on MacOS and Excel to access a mySQL database

Ever tried to access a mySQL database within Excel on macOS using the ODBC driver (64bit)? – I tried and failed. Here is my way out of the mess.

Using a Windows environment it is so pretty simple: Download ODBC driver for Windows from the mySQL Webpage, install it, open the system control -> ODBC configuration, add a DSN using input fields, test it. Next start Excel, external datasource, select DSN and voila: full access to the database.

I’ll spare you all the details of failure and just list a few of the error messages on the way to success:

The installation failed. The Installer encountered an error the caused the installation to fail. Contact the software manufacturer for assistance.

Error message if you want to install the MySQL Connector/Odbc

[iODBC][Driver Manager]Specified driver could not be loaded

Error message in Excel, if you want to address the database
And now, how it worked for me

iODBC Environment

First of all you have to install the iODBC (3.52.12 or later) environment on the OS X system before your can install the Connector/ODBC. You’ll find the installation packet here: Just download and install it. You’ll find the iODBC Administrator in „Programs -> iODBC“

ODBC/Connector mySQL

Before using the iODBC Administrator download an install the ODBC/Connector for MySQL. You’ll find the installation packet here: Now that the iODBC package is installed, this installation works without the error message „The installation failed“.

Moving the ODBC/Connector

And now a step that makes the use with Excel possible. The Microsoft Office solution under macOS is a Sandboxed application and doesn’t have access to the default installation path of the ODBC/Connector (/usr/local/mysql-connector-odbc …..). You’ll have to move the installation to /Library/ODBC … And you have to do some more modifications. I found the following script (Sam/samsgit on doing this in a perfect way:

mysql_odbc_name=$(ls "$base_src_dir" | grep -m 1 "mysql-connector-odbc")
echo "creating '$dst'"
sudo mkdir -p "$dst"
echo "copying '$src' to '$dst'"
sudo cp -af "$src/." "$dst"
echo "backing up '$odbc_ini_path' to '$odbc_ini_bak_path'"
sudo cp -f "$odbc_ini_path" "$odbc_ini_bak_path"
echo "backing up '$odbcinst_ini_path' to '$odbcinst_ini_bak_path'"
sudo cp -f "$odbcinst_ini_path" "$odbcinst_ini_bak_path"
function replace {
  sudo sed -i '' "s/$(sed 's/[^^]/[&]/g; s/\^/\\^/g' <<< "$1")/$(sed 's/[&/\]/\\&/g' <<< "$2")/g" "$3"
ansi_driver=$(ls "$dst" | grep -m 1 "^lib.*a\.so$")
unicode_driver=$(ls "$dst" | grep -m 1 "^lib.*w\.so$")
echo "updating '$old_ansi_path' to '$new_ansi_path' in '$odbc_ini_path'"
replace "$old_ansi_path" "$new_ansi_path" "$odbc_ini_path"
echo "updating '$old_ansi_path' to '$new_ansi_path' in '$odbcinst_ini_path'"
replace "$old_ansi_path" "$new_ansi_path" "$odbcinst_ini_path"
echo "updating '$old_unicode_path' to '$new_unicode_path' in '$odbc_ini_path'"
replace "$old_unicode_path" "$new_unicode_path" "$odbc_ini_path"
echo "updating '$old_unicode_path' to '$new_unicode_path' in '$odbcinst_ini_path'"
replace "$old_unicode_path" "$new_unicode_path" "$odbcinst_ini_path"

Just open a terminal window, create a new file with an editor (eg. vi <script name>) and paste the script above. After saving the file make the script executable for your OS (eg. chmod a+x <script name>). Last but not least, run the script (eg. „./<script name>).

Configure the ODBC/Connector

Now you can configure the DSN in the iODBC Administrator. Just add an User DSN:

And it works

Now you can start Excel and navigate to „data“ -> „new query“ -> „Database“ and select your DSN entry 🙂

Kommentar verfassen

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.