Mac --> QSqlDatabase: QMYSQL driver not loaded



  • Hi,

    I have this error when I want to build my program.
    I saw this problem a lot of time in forums but I don't know how I can resolve it. I work on mac Maverick.
    Nobody can help me to install driver on qt.

    Thanks


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you install the MySql client libraries ?



  • Thanks.
    Yes, I downloaded Mysql and I installed it. But Qt says me the same thing.


  • Lifetime Qt Champion

    Where's your MySql libraries installed ?

    What does otool -L on qsqlmysql.dylib return ?



  • Mysql libraries are intalled here :
    /Users/XXX/qt/5.3/plugins/sqldrivers

    @bash-3.2$ ls
    libqsqlite.dylib libqsqlmysql.dylib libqsqlodbc.dylib libqsqlpsql.dylib
    libqsqlite_debug.dylib libqsqlmysql_debug.dylib libqsqlodbc_debug.dylib libqsqlpsql_debug.dylib
    bash-3.2$ 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)
    /Users/nicolaspeyvel/Qt/5.3/clang_64/lib/QtSql.framework/Versions/5/QtSql (compatibility version 5.3.0, current version 5.3.0)
    /Users/nicolaspeyvel/Qt/5.3/clang_64/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.3.0, current version 5.3.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)@


  • Lifetime Qt Champion

    So it seems that you have everything setup correctly.

    What does QSqlDatabase::lastError() tell you ?



  • @2014-06-24 18:06:10.524 sqlbrowser[7066:507] modalSession has been exited prematurely - check for a reentrant call to endModalSession:
    2014-06-24 18:06:10.526 sqlbrowser[7066:507] -[NSApplication runModalSession:]: Use of freed session detected. Do not call runModalSession: after calling endModalSesion:.@

    @QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7@


  • Lifetime Qt Champion

    @
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
    @

    That's the standard error message when something is wrong but does

    @
    qDebug() << db.lastError().toString();
    @

    return ?



  • I have this error :

    @QSqlError("", "Driver not loaded", "Driver not loaded")@

    my code is this :

    @#include <QCoreApplication>
    #include <QtSql>
    #include <iostream>

    #define q2c(string) string.toStdString()

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setUserName("root");
    db.setPassword("root");
    db.setDatabaseName("Chrono");
    if(!db.open())
    {
    qDebug() << db.lastError();
    }
    return a.exec();
    }@

    And my qProject :
    @QT += core
    QT += sql widgets

    QT -= gui

    TARGET = sans_titre2
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp
    @


  • Lifetime Qt Champion

    Well that's a pretty unusual case since you seem to have everything in place correctly.

    Can you run your application with QT_DEBUG_PLUGINS=1 ?



  • I add
    @QT_DEBUG_PLUGINS = 1@
    in QtProject
    and I have the same error.


  • Lifetime Qt Champion

    It's not supposed to make it work but to give your more information about what happens when plugins are getting loaded.

    How did you set that environment variable ?



  • I set your code line like this :
    @QT += core
    QT += sql

    QT -= gui$

    QT_DEBUG_PLUGINS = 1

    TARGET = sans_titre2
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp
    @
    in the Qproject


  • Lifetime Qt Champion

    Sorry, I mislead you, it must be set as environment variable when you run your application. Go to Projects, select the run panel, Run environment, and add that variable there



  • I place my variable and I have a lot of stuff :
    @Found metadata in lib /Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlite.dylib, metadata=
    {
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
    "Keys": [
    "QSQLITE"
    ]
    },
    "className": "QSQLiteDriverPlugin",
    "debug": false,
    "version": 328448
    }

    Got keys from plugin meta data ("QSQLITE")
    QFactoryLoader::QFactoryLoader() looking at "/Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlite_debug.dylib"
    Found metadata in lib /Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlite_debug.dylib, metadata=
    {
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
    "Keys": [
    "QSQLITE"
    ]
    },
    "className": "QSQLiteDriverPlugin",
    "debug": true,
    "version": 328448
    }

    Got keys from plugin meta data ("QSQLITE")
    QFactoryLoader::QFactoryLoader() looking at "/Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql.dylib"
    Found metadata in lib /Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, metadata=
    {
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
    "Keys": [
    "QMYSQL3",
    "QMYSQL"
    ]
    },
    "className": "QMYSQLDriverPlugin",
    "debug": false,
    "version": 328448
    }

    Got keys from plugin meta data ("QMYSQL3", "QMYSQL")
    QFactoryLoader::QFactoryLoader() looking at "/Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib"
    Found metadata in lib /Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib, metadata=
    {
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
    "Keys": [
    "QMYSQL3",
    "QMYSQL"
    ]
    },
    "className": "QMYSQLDriverPlugin",
    "debug": true,
    "version": 328448
    }

    Got keys from plugin meta data ("QMYSQL3", "QMYSQL")
    QFactoryLoader::QFactoryLoader() looking at "/Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlodbc.dylib"
    Found metadata in lib /Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlodbc.dylib, metadata=
    {
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
    "Keys": [
    "QODBC3",
    "QODBC"
    ]
    },
    "className": "QODBCDriverPlugin",
    "debug": false,
    "version": 328448
    }

    Got keys from plugin meta data ("QODBC3", "QODBC")
    QFactoryLoader::QFactoryLoader() looking at "/Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlodbc_debug.dylib"
    Found metadata in lib /Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlodbc_debug.dylib, metadata=
    {
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
    "Keys": [
    "QODBC3",
    "QODBC"
    ]
    },
    "className": "QODBCDriverPlugin",
    "debug": true,
    "version": 328448
    }

    Got keys from plugin meta data ("QODBC3", "QODBC")
    QFactoryLoader::QFactoryLoader() looking at "/Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlpsql.dylib"
    Found metadata in lib /Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlpsql.dylib, metadata=
    {
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
    "Keys": [
    "QPSQL7",
    "QPSQL"
    ]
    },
    "className": "QPSQLDriverPlugin",
    "debug": false,
    "version": 328448
    }

    Got keys from plugin meta data ("QPSQL7", "QPSQL")
    QFactoryLoader::QFactoryLoader() looking at "/Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlpsql_debug.dylib"
    Found metadata in lib /Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlpsql_debug.dylib, metadata=
    {
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
    "Keys": [
    "QPSQL7",
    "QPSQL"
    ]
    },
    "className": "QPSQLDriverPlugin",
    "debug": true,
    "version": 328448
    }

    Got keys from plugin meta data ("QPSQL7", "QPSQL")
    QFactoryLoader::QFactoryLoader() checking directory path "/Users/nicolaspeyvel/build-sans_titre2-Desktop_Qt_5_3_0_clang_64bit-Debug/sqldrivers" ...
    loaded library "/Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql.dylib"
    QLibraryPrivate::loadPlugin failed on "/Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 5): Library not loaded: /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib
    Referenced from: /Users/nicolaspeyvel/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
    Reason: image not found)"
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

    QSqlError("", "Driver not loaded", "Driver not loaded")
    @


  • Lifetime Qt Champion

    Can you run

    @file /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib@

    ?



  • sorry but I don't have file like you, so I don't know where this lib is:
    @bash-3.2$ cd opt/X11/lib
    bash-3.2$ ls
    X11 libXmuu.1.dylib libxcb-event.1.dylib
    libAppleWM.7.dylib libXmuu.dylib libxcb-ewmh.2.dylib
    libAppleWM.dylib libXp.6.dylib libxcb-ewmh.dylib
    libFS.6.dylib libXp.dylib libxcb-glx.0.dylib
    libFS.dylib libXplugin.1.dylib libxcb-glx.dylib
    libGL.1.dylib libXplugin.dylib libxcb-icccm.4.dylib
    libGL.dylib libXpm.4.dylib libxcb-icccm.dylib
    libGLU.1.dylib libXpm.dylib libxcb-image.0.dylib
    libGLU.dylib libXrandr.2.dylib libxcb-image.dylib
    libICE.6.dylib libXrandr.dylib libxcb-keysyms.1.dylib
    libICE.dylib libXrender.1.dylib libxcb-keysyms.dylib
    libOSMesa.8.dylib libXrender.dylib libxcb-present.0.dylib
    libOSMesa.dylib libXss.1.dylib libxcb-present.dylib
    libOpenVG.1.dylib libXss.dylib libxcb-randr.0.dylib
    libOpenVG.dylib libXt.6.dylib libxcb-randr.dylib
    libSM.6.dylib libXt.dylib libxcb-record.0.dylib
    libSM.dylib libXtst.6.dylib libxcb-record.dylib
    libX11-xcb.1.dylib libXtst.dylib libxcb-render-util.0.dylib
    libX11-xcb.dylib libXv.1.dylib libxcb-render-util.dylib
    libX11.6.dylib libXv.dylib libxcb-render.0.dylib
    libX11.dylib libXvMC.1.dylib libxcb-render.dylib
    libXRes.1.dylib libXvMC.dylib libxcb-res.0.dylib
    libXRes.dylib libXvMCW.1.dylib libxcb-res.dylib
    libXTrap.6.dylib libXvMCW.dylib libxcb-screensaver.0.dylib
    libXTrap.dylib libXxf86misc.1.dylib libxcb-screensaver.dylib
    libXau.6.dylib libXxf86misc.dylib libxcb-shape.0.dylib
    libXau.dylib libXxf86vm.1.dylib libxcb-shape.dylib
    libXaw.6.dylib libXxf86vm.dylib libxcb-shm.0.dylib
    libXaw.7.dylib libcairo-script-interpreter.2.dylib libxcb-shm.dylib
    libXaw.8.dylib libcairo-script-interpreter.dylib libxcb-sync.1.dylib
    libXaw.dylib libcairo.2.dylib libxcb-sync.dylib
    libXaw3d.8.dylib libcairo.dylib libxcb-util.0.dylib
    libXaw3d.dylib libdmx.1.dylib libxcb-util.1.dylib
    libXaw6.6.dylib libdmx.dylib libxcb-util.dylib
    libXaw6.dylib libfontconfig.1.dylib libxcb-xevie.0.dylib
    libXaw7.7.dylib libfontconfig.dylib libxcb-xevie.dylib
    libXaw7.dylib libfontenc.1.dylib libxcb-xf86dri.0.dylib
    libXaw8.8.dylib libfontenc.dylib libxcb-xf86dri.dylib
    libXaw8.dylib libfreetype.6.dylib libxcb-xfixes.0.dylib
    libXcomposite.1.dylib libfreetype.dylib libxcb-xfixes.dylib
    libXcomposite.dylib libglut.3.dylib libxcb-xinerama.0.dylib
    libXcursor.1.dylib libglut.dylib libxcb-xinerama.dylib
    libXcursor.dylib libpixman-1.0.dylib libxcb-xkb.1.dylib
    libXdamage.1.dylib libpixman-1.dylib libxcb-xkb.dylib
    libXdamage.dylib libpng.3.dylib libxcb-xprint.0.dylib
    libXdmcp.6.dylib libpng.dylib libxcb-xprint.dylib
    libXdmcp.dylib libpng12.0.dylib libxcb-xtest.0.dylib
    libXevie.1.dylib libpng14.14.dylib libxcb-xtest.dylib
    libXevie.dylib libpng15.15.dylib libxcb-xv.0.dylib
    libXext.6.dylib libpng15.dylib libxcb-xv.dylib
    libXext.dylib libqsqlmysql.dylib libxcb-xvmc.0.dylib
    libXfixes.3.dylib libxcb-atom.1.dylib libxcb-xvmc.dylib
    libXfixes.dylib libxcb-aux.0.dylib libxcb.1.dylib
    libXfont.1.dylib libxcb-composite.0.dylib libxcb.dylib
    libXfont.dylib libxcb-composite.dylib libxkbfile.1.dylib
    libXfontcache.1.dylib libxcb-cursor.0.dylib libxkbfile.dylib
    libXfontcache.dylib libxcb-cursor.dylib libxkbui.1.dylib
    libXft.2.dylib libxcb-damage.0.dylib libxkbui.dylib
    libXft.dylib libxcb-damage.dylib libxshmfence.1.dylib
    libXi.6.dylib libxcb-dpms.0.dylib libxshmfence.dylib
    libXi.dylib libxcb-dpms.dylib pkgconfig
    libXinerama.1.dylib libxcb-dri2.0.dylib python2.6
    libXinerama.dylib libxcb-dri2.dylib sqldrivers
    libXmu.6.dylib libxcb-dri3.0.dylib xorg
    libXmu.dylib libxcb-dri3.dylib
    @

    In sqldrivers I have
    @bash-3.2$ cd sqldrivers/
    bash-3.2$ ls
    libqsqlite.dylib libqsqlmysql.dylib libqsqlodbc.dylib libqsqlpsql.dylib
    libqsqlite_debug.dylib libqsqlmysql_debug.dylib libqsqlodbc_debug.dylib libqsqlpsql_debug.dylib@


  • Lifetime Qt Champion

    Then how did you install MySQL ?



  • I used the installer.
    To test my databases I use MAMP


  • Lifetime Qt Champion

    Ok, so where on your system can you find a library named libmysqlclient.dylib ?



  • I found it here :
    @bash-3.2$ sudo find / -name "libmysqlclient.dylib"
    find: /dev/fd/3: Not a directory
    find: /dev/fd/4: Not a directory
    /usr/local/mysql-5.6.19-osx10.6-x86/lib/libmysqlclient.dylib@


  • Lifetime Qt Champion

    Ok ! Here we have it now. Please use install_name_tool to update the QtSql library in the framework



  • In my folder I have theses files :
    @bash-3.2$ cd usr/local/mysql-5.6.19-osx10.6-x86//lib/
    bash-3.2$ ls
    libmysqlclient.18.dylib libmysqlclient_r.dylib
    libmysqlclient.a libmysqld-debug.a
    libmysqlclient.dylib libmysqld.a
    libmysqlclient_r.18.dylib libmysqlservices.a
    libmysqlclient_r.a plugin@

    What will I do ?


  • Lifetime Qt Champion

    using install_name_tool, correct the path /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib in libqsqlmysql.dylib with /usr/local/mysql-5.6.19-osx10.6-x86//lib/libmysqlclient.18.dylib



  • When I'm in the correct directory, what lines I must insert in the terminal ?


  • Lifetime Qt Champion

    install_name_tool -change old_path new_path libqsqlmysql.dylib



  • Hello SGaist,
    I have tried your solution, with this instruction:
    install_name_tool -change /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib /Applications/mampstack-5.4.26-0/mysql/lib/libmysqlclient.dylib libqsqlmysql.dylib

    but during debug I receive this message:
    @
    QFactoryLoader::QFactoryLoader() checking directory path "/Users/warcomeb/Projects/build-LabOrToolGui-Desktop_Qt_5_2_1_clang_64bit/Debug/LabOrTool.app/Contents/MacOS/sqldrivers" ...
    loaded library "/Users/warcomeb/Qt5.2.1/5.2.1/clang_64/plugins/sqldrivers/libqsqlmysql.dylib"
    QSqlError(-1, "", "")
    Database non connected!
    QSqlError(2005, "QMYSQL: Unable to connect", "Unknown MySQL server host 'localhost:3306' (2)") @

    I have followed all step that you wrote previously!
    Can you help me?


  • Lifetime Qt Champion

    Is your server running ?

    Also, if it was deployed correctly, you should need to correct the path by hand. The client library should be already copied in your bundle



  • Yes, the server is running!
    I have added setPort to my database configuration and now it work!

    Thanks!
    Marco



  • It's not work for my :'(

    @install_name_tool -change /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib /Applications/mampstack-5.4.26-0/mysql/lib/libmysqlclient.dylib libqsqlmysql.dylib
    error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: can't open file: libqsqlmysql.dylib (No such file or directory)
    @

    what I must to do ? I'm on Yosemite now.


  • Lifetime Qt Champion

    As silly as it may sound, use the correct path to libqsqlmysql.dylib



  • I don't understand what you mean.

    One other thing when I run my project I have these lines :
    @QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7@

    If it's available why it's not loaded.


  • Lifetime Qt Champion

    @can't open file: libqsqlmysql.dylib (No such file or directory)@

    You didn't run the command in the right folder since libqsqlmysql.dylib could not be found.

    That generally happens when the plugin can't be loaded because e.g. it can't find one of the its dependencies


Log in to reply
 

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