A vanilla intall of Qt, using either their online or offline installers, comes with sql plugins. Their however depend on libraries that may not be installed on your system.


I came with this issue trying to use the QMYSQL driver.


jwintz@inextremis ~/Development/112m-server/build $ ./bin/112m-server

QSqlDatabase: QMYSQL driver not loaded

QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

So I checkout out the dependencies of the plugin qsqlmysql:


jwintz@inextremis ~/Development/qt/5.5/clang_64/plugins/sqldrivers $ otool -L libqsqlmysql.dylib

libqsqlmysql.dylib:

  libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)

  /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)

  /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)

  @rpath/QtSql.framework/Versions/5/QtSql (compatibility version 5.5.0, current version 5.5.1)

  @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.5.0, current version 5.5.1)

  /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)

  /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)

  /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)

  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

Note the dependency /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib which assumes that one has mysql installed using either Fink or Macports most probably. So if you don’t have or want to use Macports, you’ll have to patch the library to use another instance of the libmysqlclient.


For many reasons, I personally prefer Homebrew, which is a very smart tool (try its doctor option for example).


jwintz@inextremis ~/Development/112m-server/build $ brew install mysql

Then, locate your libmysqclient.dylib path.


jwintz@inextremis /usr/local/Cellar $ find . | grep libmysqlclient

./mysql/5.7.10/lib/libmysqlclient.20.dylib

./mysql/5.7.10/lib/libmysqlclient.a

./mysql/5.7.10/lib/libmysqlclient.dylib

The last step is then to patch the qt mysql plugin to use this newly installed instance.



jwintz@inextremis ~/Development/qt/5.5/clang_64/plugins/sqldrivers $ install_name_tool -change /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib /usr/local/Cellar/mysql/5.7.10/lib/libmysqlclient.dylib libqsqlmysql.dylib

Enjoy and save some time !