download mysql-connector-c-6.1.5-winx64.zip or newer
unpac in the same directory
init mex if you need using: mex -setup
mex -Imysql-connector-c-6.1.5-winx64\include\ ...
-llibmysql -O mysql.cpp
copy libmysql.dll in the same dir as your compiled mysql.mexw64
this works about 20% faster than jdbc version
After going through all comments below, here's are some streamlined instrutions for installing under OSX Mavericks (R2014a).
Step 1 - Install a mysql distribution to get the mysql client libs and headers:
% sudo bash <(curl -Ls http://git.io/eUx7rg)
As of today, this install mysql-5.6.19 -- note the version number -- you need to make sure it matches the command below. You can verify the version installed by looking in /usr/local for mysql-VERSION-osx...
to your .bashrc/.bash_profile (or matlab startup script).
Two things that aren't clear in the comments below are (1) mysql version number (currently 5.6.19) can change, so you need to check and (2) the DYLD_LIBRARY_PATH needs to be set to USE the mex file, not to compile it.
Sorry to write too much... I found the error. I was compiling with Xcode 5.1... By compiling with Xcode 5.0.2 it worked. Before I also tried with queryMySQL but to retrieve the data was too slow. This is much complicate to install but at the end works so much faster than queryMySQL.