Qt cannot connect to mysql, libqsqlmysql.dylib is not loading. HELP please.

  • Hi every one. This is my first post in this forum. I hope someone gives me some clues on how to resolve this issue.
    I have gone through the documentation of building Qt and mysql, I also built the the drivers successfully but after installing them in the correct directory I can't see mysql driver in the out put string.

    please see this link for further info:

    I have built the qt libraries and qt creator on my computer (using the method recommended in the Qt documentation, qmake, make, ...)

    I also compiled mysql on my computer using mysql online documentation:


    I managed to create libqsqlmysql.dylib and libqsqlmysql_debug.dylib and installed them in


    where my qt is installed. when i run the following code
    #include <QtCore/QCoreApplication>
    #include <QtSql>
    #include <QtDebug>

    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);
    QSqlDatabase * db = new QSqlDatabase;

    qDebug() << db->drivers();
    qDebug() << QCoreApplication::libraryPaths();
    return 1;

    i only get
    ("QSQLITE", "QODBC3", "QODBC")

    why mysql's driver is not loading?

    These three drivers in addition to the one that I installed are all there. Here is ls result:

    dhcp-85-5:sqldrivers ***$ ls
    libqsqlite.dylib libqsqlmysql_debug.dylib
    libqsqlite_debug.dylib libqsqlodbc.dylib
    libqsqlmysql.dylib libqsqlodbc_debug.dylib

    I used otool before and this is what i got:
    libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
    libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
    /usr/local/Trolltech/Qt-4.7.3/lib/QtSql.framework/Versions/4/QtSql (compatibility version 4.7.0, current version 4.7.3)
    /usr/local/Trolltech/Qt-4.7.3/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.7.0, current version 4.7.3)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 830.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)

    i also tried echo $DYLD_LIBRARY_PATH and i get empty string. Would you please tell me what value this should be set to?

  • Just a guess: libmysqlclient.18.dylib cannot be found. Add the path to the directory containing libmysqlclient.18.dylib to DYLD_LIBRARY_PATH.

  • Thank you Volker,
    My question is I don't know where to go and set DYLD_LIBRARY_PATH.
    When I use terminal (bash) in mac it only sets it for the current terminal and when I close it every thing is gone.

    There should be a file somewhere so that I can edit it for the user or globally but i don't know its name and location

    can you help me with that please.

  • The best way would be to copy the lib into the frameworks folder inside the app and use install_name_tool to change the path. Have a look at the "Mac Deployment":http://developer.qt.nokia.com/doc/qt-4.7/deployment-mac.html page of the Qt docs on some information how to do this.

  • Thank you Volker :),
    I solved the problem. You were right, I used ln to put a link of libmysqlclient.18.dylib in mac's lib folder.
    Also the link you just put is awesome. Thanks a lot.

  • If you want to ship that application to someone else, you'd better put the libs into the application bundle (if allowed by the license, of course).

  • I appreciate your helps and consider this. Thank you so much :)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.