Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded



  • I have the following code to connect to a MariaDB database on my local development system. The development system is an iMAC:

    Model Name:  iMac
    Model Identifier:  iMac17,1
    Processor Name:  Intel Core i7
    Processor Speed:  4 GHz
    Number of Processors: 1
    Total Number of Cores: 4
    L2 Cache (per Core):  256 KB
    L3 Cache:  8 MB
    Memory: 16 GB
    Boot ROM Version: IM171.0157.B00
    SMC Version (system):	2.34f2
    

    I am trying to connect to the database with:

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("Simons-iMac.local");
    db.setDatabaseName("timekpr");
    db.setUserName("timekpr");
    db.setPassword("timekpr");
    
    if ( !db.open() ) {
        qDebug() << db.lastError();
        qFatal( "Failed to connect." );
    }
    qDebug( "Connected!" );
    

    Unfortunately, the result is:

    2018-10-04 18:36:22.414186+0100 SimonQtWidgets[23857:951442] [default] Unable to load Info.plist exceptions (eGPUOverrides)
    2018-10-04 18:36:28.995915+0100 SimonQtWidgets[23857:951353] QSqlDatabase: QMYSQL driver not loaded
    2018-10-04 18:36:28.995977+0100 SimonQtWidgets[23857:951353] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    2018-10-04 18:36:34.533463+0100 SimonQtWidgets[23857:951353] QSqlError("", "Driver not loaded", "Driver not loaded")
    2018-10-04 18:36:35.207312+0100 SimonQtWidgets[23857:951353] Failed to connect.
    

    How do I resolve this issue? I can connect to the database using NodeJs on the same system with exactly the same credentials.



  • @SPlatten said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:

    libmysqlclient.20.dylib

    @SGaist , I managed to progress the issue, this is what I did:

    Manually create the required folder structure, from /usr/local:

    sudo mkdir mysql
    cd mysql
    sudo mkdir lib
    cd lib
    

    Then create a symbolic link to the required library:

    sudo ln -s /usr/local/lib/libmysqlclient.dylib /usr/local/mysql/lib/libmysqlclient.20.dylib
    

    Now debugging the same project, the call to open still fails with:

    2018-10-12 08:44:19.696706+0100 SimonQtWidgets[1253:117317] loaded library "/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib"
    2018-10-12 08:44:39.663805+0100 SimonQtWidgets[1253:117317] QSqlError("1130", "QMYSQL: Unable to connect", "Host '192.168.1.158' is not allowed to connect to this MariaDB server")
    2018-10-12 08:44:40.409469+0100 SimonQtWidgets[1253:117317] Failed to connect.
    

    Now resolved, the issue here was that the call to setHostName was using the host name of the system, I changed this to localhost and now everything works.


  • Lifetime Qt Champion

    Hi,

    This question has already been asked many times on this forum. Please search it a bit (although you might stumble on more posts about PostgreSQL on macOS)

    In any case, run otool -L on the MySQL Qt plugin. You'll likely get at least one path pointing to a location where it can't find the MySQL client library. Use install_name_tool to fix that path and point it to your MariaDB client library.

    In any case, you can use the QT_DEBUG_PLUGINS environment variable set to 1 to get more information about what happens when your application tries to load a plugin.



  • I took your advice and there are many many people asking the same thing, I couldn't find a simple solution for me on the macOS. Why is this such a problem? The instance of MariaDB on my system works fine and I can open it using "wine" and HeidiSQL without any problems, but I cannot connect to it with QSQLDababase.

    I have Q5.11.2 installed in ~/Qt/5.11.2/

    This is what I tried:

    cd  Qt/5.11.2/clang_64/plugins/sqldrivers/
    

    In this folder I have the following:

    libqsqlite.dylib
    libqsqlite.dylib.dSYM
    libqsqlite_debug.dylib
    libqsqlmysql.dylib
    libqsqlmysql.dylib.dSYM
    libqsqlmysql_debug.dylib
    libqsqlmysql_debug.dylib.dSYM
    libqsqlpsql.dylib
    libqsqlpsql.dylib.dSYM
    libqsqlpsql_debug.dylib
    libqsqlpsql_debug.dylib.dSYM
    

    I tried:

    otool -L libqsqlmysql.dylib
    

    Which results in:

    libqsqlmysql.dylib:
    	libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
    	@rpath/QtSql.framework/Versions/5/QtSql (compatibility version 5.11.0, current version 5.11.2)
    	@rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.11.0, current version 5.11.2)
    	/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/local/mysql/lib/libmysqlclient.20.dylib (compatibility version 20.0.0, current version 20.0.0)
    	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
    	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)
    

    then:

    otool -L libqsqlmysql_debug.dylib
    

    Which results in:

    libqsqlmysql_debug.dylib:
    	libqsqlmysql_debug.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/QtSql.framework/Versions/5/QtSql (compatibility version 5.11.0, current version 5.11.2)
    @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.11.0, current version 5.11.2)
    	/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/local/mysql/lib/libmysqlclient.20.dylib (compatibility version 20.0.0, current version 20.0.0)
    	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
    	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)
    

    I then rebuilt the project, results almost the same:

    18:20:30: Debugging starts
    2018-10-08 18:20:34.165604+0100 SimonQtWidgets[750:27393] [default] Unable to load Info.plist exceptions (eGPUOverrides)
    2018-10-08 18:20:37.754057+0100 SimonQtWidgets[750:27293] QSqlDatabase: QMYSQL driver not loaded
    2018-10-08 18:20:37.754278+0100 SimonQtWidgets[750:27293] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    2018-10-08 18:20:42.086803+0100 SimonQtWidgets[750:27293] QSqlError("", "Driver not loaded", "Driver not loaded")
    2018-10-08 18:20:43.026402+0100 SimonQtWidgets[750:27293] Failed to connect.
    

    Can anyone help?


  • Lifetime Qt Champion

    What do you get if you start your application with the QT_DEBUG_PLUGINS environment variable set to 1 ?



  • @SGaist said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:

    QT_DEBUG_PLUGINS

    I did this:

    1. Opened a terminal

    2. Typed: export QT_DEBUG_PLUGINS=1

    3. Started application in Qt with debug and single stepped the following lines:

      QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
      db.setHostName("Simons-iMac.local");
      db.setDatabaseName("timekpr");
      db.setUserName("timekpr");
      db.setPassword("timekpr");
      

    When I stepped over the first line I got:

        2018-10-09 08:28:39.328815+0100 SimonQtWidgets[934:47867] QSqlDatabase: QMYSQL driver not loaded

  • Lifetime Qt Champion

    What would be interesting is to have the log that was generated about the plugin loading phase.



  • What do I need to do in order to get you that log?


  • Lifetime Qt Champion

    Since you are using Qt Creator, look at the output panel.



  • Specifically which panel are you referring to?

    I don't see anything in the "Debugger Console", if I enable the "Debugger Log" I see:

    dNOTE: INFERIOR RUN REQUESTED
    sRun requested...
    dState changed from InferiorStopOk(11) to InferiorRunRequested(7) [master]
    <73executeNext({"token":73})

    (lldb) script theDumper.executeNext({"token":73})
    @
    result={token="73",}@
    @
    event={type="1",data="0x7fea5d161f90 Event: broadcaster = 0x7fea5a85fa38 (lldb.process), type = 0x00000001 (state-changed), data = { process = 0x7fea5a85fa00 (pid = 2567), state = running}",msg="None",flavor="Process::ProcessEventData",state="running",bp="No value"}@
    @
    state="running"@
    @
    event={type="4",data="0x7fea5b425a58 Event: broadcaster = 0x7fea5a85fa38 (lldb.process), type = 0x00000004 (stdout-available), data = { process = 0x7fea5a85fa00 (pid = 2567), state = running}",msg="None",flavor="Process::ProcessEventData",state="running",bp="No value"}@
    @
    output={channel="stdout",data="323031382d31302d30392031303a30343a30352e3739383731312b303130302053696d6f6e5174576964676574735b323536373a3338393637385d205153716c44617461626173653a20514d5953514c20647269766572206e6f74206c6f616465640d0a323031382d31302d30392031303a30343a30352e3739383736372b303130302053696d6f6e5174576964676574735b323536373a3338393637385d205153716c44617461626173653a20617661696c61626c6520647269766572733a205153514c49544520514d5953514c20514d5953514c3320515053514c20515053514c370d0a"}@
    @
    event={type="4",data="0x7fea5d04e788 Event: broadcaster = 0x7fea5a85fa38 (lldb.process), type = 0x00000004 (stdout-available), data = { process = 0x7fea5a85fa00 (pid = 2567), state = running}",msg="None",flavor="Process::ProcessEventData",state="running",bp="No value"}@
    @
    output={channel="stdout",data=""}@
    73^
    dNOTE: INFERIOR RUN OK
    sRunning.
    dState changed from InferiorRunRequested(7) to InferiorRunOk(8) [master]
    2018-10-09 10:04:05.798711+0100 SimonQtWidgets[2567:389678] QSqlDatabase: QMYSQL driver not loaded
    2018-10-09 10:04:05.798767+0100 SimonQtWidgets[2567:389678] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    @
    event={type="1",data="0x7fea5d071a40 Event: broadcaster = 0x7fea5a85fa38 (lldb.process), type = 0x00000001 (state-changed), data = { process = 0x7fea5a85fa00 (pid = 2567), state = stopped}",msg="None",flavor="Process::ProcessEventData",state="stopped",bp="No value"}@
    @
    state="stopped"@
    dNOTE: INFERIOR SPONTANEOUS STOP
    sStopped.
    dState changed from InferiorRunOk(8) to InferiorStopOk(11) [master]
    <74fetchThreads({"token":74})

    (lldb) script theDumper.fetchThreads({"token":74})
    @
    result={token="74",threads=[{id="389678",index="0",details="com.apple.main-thread",stop-reason="plancomplete",state="unknown",name="None",frame={pc="0x1000038d6",addr="0x1000038d6",fp="0x7ffeefbffa00",func="main",line="13",fullname="/Users/simonplatten/build-SimonQtWidgets-Desktop_Qt_5_11_2_clang_64bit-Debug/../SimonQtWidgets/main.cpp",file="/Users/simonplatten/build-SimonQtWidgets-Desktop_Qt_5_11_2_clang_64bit-Debug/../SimonQtWidgets/main.cpp"}},{id="389776",index="1",details="None",stop-reason="none",state="unknown",name="None",frame={pc="0x7fff753495be",addr="0x7fff753495be",fp="0x70000e3fefd0",func="__workq_kernreturn",line="0",fullname="",file=""}},{id="389777",index="2",details="None",stop-reason="none",state="unknown",name="None",frame={pc="0x7fff753495be",addr="0x7fff753495be",fp="0x70000e481fd0",func="__workq_kernreturn",line="0",fullname="",file=""}},{id="389783",index="3",details="None",stop-reason="none",state="unknown",name="None",frame={pc="0x7fff753495be",addr="0x7fff753495be",fp="0x70000e504fd0",func="__workq_kernreturn",line="0",fullname="",file=""}},],current-thread-id="389678"}@
    74^
    <75fetchStack({"context":"","nativemixed":0,"stacklimit":20,"token":75})

    (lldb) script theDumper.fetchStack({"context":"","nativemixed":0,"stacklimit":20,"token":75})
    @
    result={token="75",stack={current-thread="389678",frames=[{pc="0x1000038d6",level="0",address="0x1000038d6",function="main",line="13",file="/Users/simonplatten/build-SimonQtWidgets-Desktop_Qt_5_11_2_clang_64bit-Debug/../SimonQtWidgets/main.cpp"},{pc="0x7fff7520f085",level="1",address="0x7fff7520f085",function="start",line="0",file=""},{pc="0x7fff7520f085",level="2",address="0x7fff7520f085",function="start",line="0",file=""},],hasmore="0",limit="20"}}@
    75^
    <76activateFrame({"index":0,"thread":389678,"token":76})
    <77fetchVariables({"autoderef":1,"context":"","displaystringlimit":"100","dyntype":1,"expanded":["inspect","local","watch","return"],"fancy":1,"formats":{},"nativemixed":0,"partialvar":"","passexceptions":0,"qobjectnames":1,"stringcutoff":"10000","token":77,"typeformats":{},"watchers":[]})
    (lldb) script theDumper.activateFrame({"index":0,"thread":389678,"token":76})
    @
    token("76")@
    @
    result={token="76",}@
    (lldb) script theDumper.fetchVariables({"autoderef":1,"context":"","displaystringlimit":"100","dyntype":1,"expanded":["inspect","local","watch","return"],"fancy":1,"formats":{},"nativemixed":0,"partialvar":"","passexceptions":0,"qobjectnames":1,"stringcutoff":"10000","token":77,"typeformats":{},"watchers":[]})
    @
    result={token="77",data=[{name="[statics]",iname="local.[statics]",numchild="1",value="",},{iname="local.db",name="db",address="0x7ffeefbff988",numchild="1",type="QSqlDatabase",value="",},{iname="local.w",name="w",address="0x7ffeefbff9a0",numchild="1",type="clsMainWnd",valueencoded="utf16",value="63006c0073004d00610069006e0057006e006400",},{iname="local.a",name="a",address="0x7ffeefbff9e0",numchild="1",type="QApplication",value="",},{iname="local.argv",name="argv",numchild="1",type="char **",valueencoded="itemcount",value="1",},{iname="local.argc",name="argc",address="0x7ffeefbff9f8",numchild="0",type="int",value="1",},],partial="0"}@
    76^
    77^
    <Rebuild Watchmodel 12 @ 10:04:06.112 [11580ms] >
    sFinished retrieving data



  • @SGaist , is this the output you were referring to?


  • Lifetime Qt Champion

    No, I never mentioned the debugger output. It's the application output panel that you must take a look at.



  • @SGaist, the contents of the application output panel was posted with my first post:

       2018-10-09 13:18:16.095404+0100 SimonQtWidgets[2734:287529] [default] Unable to load Info.plist exceptions (eGPUOverrides)
       2018-10-09 13:18:20.493598+0100 SimonQtWidgets[2734:287440] QSqlDatabase: QMYSQL driver not loaded
       2018-10-09 13:18:20.493843+0100 SimonQtWidgets[2734:287440] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
       2018-10-09 13:19:25.430180+0100 SimonQtWidgets[2734:287440] QSqlError("", "Driver not loaded", "Driver not loaded")
       2018-10-09 13:19:25.986168+0100 SimonQtWidgets[2734:287440] Failed to connect.

  • Lifetime Qt Champion

    Where did you define QT_DEBUG_PLUGINS ?



  • @SGaist, I did the following in a terminal window:

        open ~/.bash_profile
    

    In the editor, the bash_profile file was empty I added:

        export QT_DEBUG_PLUGINS=1
    

    Saved the file and closed the editor. I then ran:

        source ~/.bash_profile
    

    I closed the terminal, then re-opened to check that the variable was present by typing:

        export
    

    This is what was displayed:

        declare -x Apple_PubSub_Socket_Render="/private/tmp/com.apple.launchd.hLeo6KAahB/Render"
        declare -x DISPLAY="/private/tmp/com.apple.launchd.FHCnpoFY18/org.macosforge.xquartz:0"
        declare -x HOME="/Users/simonplatten"
        declare -x LANG="en_GB.UTF-8"
        declare -x LOGNAME="simonplatten"
        declare -x OLDPWD
        declare -x         PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands"
        declare -x PWD="/Users/simonplatten"
        declare -x QT_DEBUG_PLUGINS="1"
        declare -x SHELL="/bin/bash"
        declare -x SHLVL="1"
        declare -x SSH_AUTH_SOCK="/private/tmp/com.apple.launchd.DmRhtwquji/Listeners"
        declare -x TERM="xterm-256color"
        declare -x TERM_PROGRAM="Apple_Terminal"
        declare -x TERM_PROGRAM_VERSION="421"
        declare -x TERM_SESSION_ID="FDD4C847-385E-449E-A882-C0AC074D406E"
        declare -x TMPDIR="/var/folders/sr/s5hzkrzs7n92phmkzbrs0g_r0000gn/T/"
        declare -x USER="simonplatten"
        declare -x XPC_FLAGS="0x0"
        declare -x XPC_SERVICE_NAME="0"

  • Lifetime Qt Champion

    You should rather do that in the Run part of the Project panel.

    Because unless you either logged out or restart Qt Creator from the same terminal you ran your export from, it won't see the new variable.



  • @SGaist , can you guide me please I'm not sure how to do that.


  • Lifetime Qt Champion

    It's shown the Qt Creator documentation.



  • @SGaist , I'm struggling with the documentation, the version of Qt Creator I'm using is:

    Qt Creator 4.7.0-rc1 (4.6.84)

    From the link posted I don't see, Projects > Build & Run > Run

    How do I get to this section?

    [Edit], found it, I'm so blind, I was looking for a menu option, it was right in front of me on the left vertical tool bar.



  • @SPlatten said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:

    QT_DEBUG_PLUGINS

    @SGaist , this is the output when the QT_DEBUG_PLUGINS is correctly added, I think I've isolated the problem, but not sure why its looking for this file and it doesn't exist::

    2018-10-10 10:30:42.060973+0100 SimonQtWidgets[2001:286805] Got keys from plugin meta data ("QPSQL7", "QPSQL")
    2018-10-10 10:30:42.060985+0100 SimonQtWidgets[2001:286805] QFactoryLoader::QFactoryLoader() checking directory path "/Users/simonplatten/build-SimonQtWidgets-Desktop_Qt_5_11_2_clang_64bit-Debug/SimonQtWidgets.app/Contents/MacOS/sqldrivers" ...
    2018-10-10 10:30:42.063252+0100 SimonQtWidgets[2001:286805] Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
      Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
      Reason: image not found)
    2018-10-10 10:30:42.063276+0100 SimonQtWidgets[2001:286805] QLibraryPrivate::loadPlugin failed on "/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib\n  Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib\n  Reason: image not found)"
    2018-10-10 10:30:42.0
    63293+0100 SimonQtWidgets[2001:286805] QSqlDatabase: QMYSQL driver not loaded
    2018-10-10 10:30:42.063465+0100 SimonQtWidgets[2001:286805] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    

    The file it appears to be looking for which doesn't exist:

        /usr/local/mysql/lib/libmysqlclient.20.dylib
    

    There is no mysql folder in /usr/local/

    I just ran:

        find / -name mysql
    

    It returned:

        /usr/local/bin/mysql
    

    There are also:

    /usr/local/Cellar/mariadb/10.1.17/bin/mysql
    /usr/local/Cellar/mariadb/10.1.17/include/mysql
    /usr/local/Cellar/mariadb/10.1.17/share/mysql
    /usr/local/Cellar/mariadb/10.2.6/bin/mysql
    /usr/local/Cellar/mariadb/10.2.6/include/mysql
    /usr/local/Cellar/mariadb/10.2.6/include/mysql/mysql
    /usr/local/Cellar/mariadb/10.2.6/.bottle/etc/init.d/mysql
    /usr/local/Cellar/mariadb/10.2.6/.bottle/etc/logrotate.d/mysql
    /usr/local/Cellar/mariadb/10.2.6/share/mysql
    

    I also found this in share:

    lrwxr-xr-x    1 simonplatten  admin     36 10 Jun  2017 mysql -> ../Cellar/mariadb/10.2.6/share/mysql
    


  • Please make sure you complie the Qmysql plugin in qtbase folder

    Link x86 libs or x64 libs with whatever mysql you have installed on your system.

    Copy sqldriver folder to complier folder

    Should fix all sql drivers not finding the correct path locations.

    Also make sure you override the static qmysql plugins as there are static ones that come shipping with it.



  • @Sunfluxgames , I copied:

    libqsqlmysql.dylib
    

    to:

    ~/build-SimonQtWidgets-Desktop_Qt_5_11_2_clang_64bit-Debug
    

    The problem and reported errors haven't changed, still the same.



  • @SPlatten
    I do not use Mac or compile Qt.

    But it seems to me that the error message:

    Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
    

    is unequivocal. You need a libmysqlclient.20.dylib. (Moving just libqsqlmysql.dylib to somewhere is not going to address this.)

    Try Googling for libqsqlmysql. There are others asking about this being missing under Linux/MacOS. You may need to download it (apt-get under MacOS? I have no idea) given what you show from your find and/or see e.g. https://afshinm.name/2016/02/05/how-to-fix-library-not-loaded-libmysqlclient-18-dylib-in-mac-os-x/



  • ~/Qt/5.11.2/clang_64/bin/qmake "INCLUDEPATH += /usr/local/mysql/include/" "LIBS += -L/usr/local/mysql/" mysql.pro
    

    Complie mysql.pro in qtbase/sqldrivers

    And then:

    cp ~/Qt/5.11.2/Src/qtbase/plugins/sqldrivers/ ~/Qt/5.11.2/clang_64/plugins/sqldrivers/
    

    Also might need to copy them to the creator folder as well to debug inside creator.



  • @Sunfluxgames , there i no /usr/local/mysql folder on my system, its MariaDB, when I ran:

        ~./Qt/5.11.2/clang_64/bin/qmake "INCLUDEPATH += /usr/local/mysql/include/" "LIBS += -L/usr/local/mysql/" mysql.pro
    

    I got:

        Cannot find file: mysql.pro.

  • Lifetime Qt Champion

    Before trying to build anything (you need to first download the sources for that). Please run your application with the QT_DEBUG_PLUGINS environment variable set to 1.

    Click on the Project button on the vertical toolbar on the left of Qt Creator, and there you'll find the Build and Run settings. Modify the Environment in the Run settings.



  • @SGaist , I did that, hasn't helped.


  • Lifetime Qt Champion

    It's not supposed to change anything in the application execution. The goal is to provide you with additional information about what is happening when plugins are getting or not loaded and from there help find what might be going wrong.



  • @SGaist said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:

    QT_DEBUG_PLUGINS

    With QT_DEBUG_PLUGINS added to the environment the output when single stepping over:

        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    

    Is:

    2018-10-11 08:28:13.253913+0100 SimonQtWidgets[1031:41669] Got keys from plugin meta data ("QPSQL7", "QPSQL")
    2018-10-11 08:28:13.253927+0100 SimonQtWidgets[1031:41669] QFactoryLoader::QFactoryLoader() checking directory path "/Users/simonplatten/build-SimonQtWidgets-Desktop_Qt_5_11_2_clang_64bit-Debug/SimonQtWidgets.app/Contents/MacOS/sqldrivers" ...
    2018-10-11 08:28:13.255823+0100 SimonQtWidgets[1031:41669] Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
      Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
      Reason: image not found)
    2018-10-11 08:28:13.255844+0100 SimonQtWidgets[1031:41669] QLibraryPrivate::loadPlugin failed on "/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib\n  Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib\n  Reason: image not found)"
    2018-10-11 08:28:13.255
    859+0100 SimonQtWidgets[1031:41669] QSqlDatabase: QMYSQL driver not loaded
    2018-10-11 08:28:13.255885+0100 SimonQtWidgets[1031:41669] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    

  • Lifetime Qt Champion

    @SPlatten said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:

    Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib

    Do you have this lib in that location?



  • @jsulm , No, I've no idea what this library is or where is comes from. The path /usr/local/mysql doesn't exist.


  • Lifetime Qt Champion

    @SPlatten This is the MySQL client library which is used by Qt to access MySQL databases. You need it if you want to use MySQL.



  • @jsulm said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:

    libmysqlclient.20.dylib

    I've found what I think is the correct library on my system:

        /usr/local/Cellar/mariadb/10.2.6/lib/libmariadb.dylib
    

    I then tried:

        sudo ln -s /usr/local/Cellar/mariadb/10.2.6/lib/libmariadb.dylib /usr/local/lib/libmysqlclient.20.dylib
    

    Re-ran in debug and the problem has changed, looks like I'm using the wrong library now:

    2018-10-11 09:15:08.331712+0100 SimonQtWidgets[1644:135071] Got keys from plugin meta data ("QPSQL7", "QPSQL")
    2018-10-11 09:15:08.331726+0100 SimonQtWidgets[1644:135071] QFactoryLoader::QFactoryLoader() checking directory path "/Users/simonplatten/build-SimonQtWidgets-Desktop_Qt_5_11_2_clang_64bit-Debug/SimonQtWidgets.app/Contents/MacOS/sqldrivers" ...
    2018-10-11 09:15:08.347152+0100 SimonQtWidgets[1644:135071] Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
      Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
      Reason: Incompatible library version: libqsqlmysql.dylib requires version 20.0.0 or later, but libmysqlclient.20.dylib provides version 3.0.0)
    2018-10-11 09:15:08.347182+0100 SimonQtWidgets[1644:135071] QLibraryPrivate::loadPlugin failed on "/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib\n  Referenced from: /Users/sim
    onplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib\n  Reason: Incompatible library version: libqsqlmysql.dylib requires version 20.0.0 or later, but libmysqlclient.20.dylib provides version 3.0.0)"
    2018-10-11 09:15:08.347201+0100 SimonQtWidgets[1644:135071] QSqlDatabase: QMYSQL driver not loaded
    2018-10-11 09:15:08.347228+0100 SimonQtWidgets[1644:135071] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    

  • Lifetime Qt Champion

    Don't use ln that won't help, use install_name_tool and update the path in libqsqlmysql.dylib to match what you have on your system.



  • @SGaist, thank you, do you have an example? How do I achieve this?


  • Lifetime Qt Champion

    Did you read the tool's help ?

    install_name_tool -change /usr/local/mysql/lib/libmysqlclient.20.dylib /path/to/mariadb/libmariadbclient.X.dylib /Users/hasan/Qt5.9.1/5.9.1/clang_64/plugins/sqldrivers/libqsqlmysql.dylib

    Note that MariaDB should be a drop-in replacement however I haven't tried to "re-link" to a library that has different name (just a different compatible version number) so you may have other surprises.



  • @SPlatten said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:

    2018-10-11 09:15:08.331712+0100 SimonQtWidgets[1644:135071] Got keys from plugin meta data ("QPSQL7", "QPSQL")
    2018-10-11 09:15:08.331726+0100 SimonQtWidgets[1644:135071] QFactoryLoader::QFact

    @SGaist

    I'm struggling, the only libmariadbclient I can find on my entire system is:

        /usr/local/Cellar/mariadb/10.2.6/lib/libmariadbclient.a

  • Lifetime Qt Champion

    Then that's something you have to check with the brew folks.



  • @SGaist , I was looking for an .so library, I've now learnt that a .dylib is the mac os equivalent.

    The database I'm using is MariaDB, I've just updated this using:

     brew upgrade mariadb
    

    Then:

    brew services restart mariadb
    

    This has added:

    /usr/local/Cellar/mariadb/10.3.10/lib
    

    Containing:

    -rwxr-xr-x  1 simonplatten  staff  1425020 13 Sep 05:40 libqsqlite.dylib
    drwxr-xr-x  3 simonplatten  staff       96  4 Oct 13:26 libqsqlite.dylib.dSYM
    -rwxr-xr-x  1 simonplatten  staff  1435972 13 Sep 05:38 libqsqlite_debug.dylib
    drwxr-xr-x  3 simonplatten  staff       96  4 Oct 13:26 libqsqlite_debug.dylib.dSYM
    -rwxr-xr-x  1 simonplatten  staff    79864 13 Sep 05:40 libqsqlmysql.dylib
    drwxr-xr-x  3 simonplatten  staff       96  4 Oct 13:26 libqsqlmysql.dylib.dSYM
    -rwxr-xr-x  1 simonplatten  staff   137448 13 Sep 05:38 libqsqlmysql_debug.dylib
    drwxr-xr-x  3 simonplatten  staff       96  4 Oct 13:26 libqsqlmysql_debug.dylib.dSYM
    -rwxr-xr-x  1 simonplatten  staff    88980 13 Sep 05:40 libqsqlpsql.dylib
    drwxr-xr-x  3 simonplatten  staff       96  4 Oct 13:26 libqsqlpsql.dylib.dSYM
    -rwxr-xr-x  1 simonplatten  staff   138612 13 Sep 05:38 libqsqlpsql_debug.dylib
    drwxr-xr-x  3 simonplatten  staff       96  4 Oct 13:26 libqsqlpsql_debug.dylib.dSYM
    

    Looking at the debug output from the Application Output:

    2018-10-12 02:33:13.197110+0100 SimonQtWidgets[6965:134266] Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
      Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
      Reason: image not found)
    

    Why is it trying to load libmysqlclient.20.dylib ?

    The next line in the Application output:

    2018-10-12 02:33:13.197133+0100 SimonQtWidgets[6965:134266] QLibraryPrivate::loadPlugin failed on "/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/
    

    Then:

    (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib\n  Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib\n  Reason: image not found)"
    2018-10-12 02:33:13.1
    97150+0100 SimonQtWidgets[6965:134266] QSqlDatabase: QMYSQL driver not loaded
    


  • @SPlatten said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:

    libmysqlclient.20.dylib

    @SGaist , I managed to progress the issue, this is what I did:

    Manually create the required folder structure, from /usr/local:

    sudo mkdir mysql
    cd mysql
    sudo mkdir lib
    cd lib
    

    Then create a symbolic link to the required library:

    sudo ln -s /usr/local/lib/libmysqlclient.dylib /usr/local/mysql/lib/libmysqlclient.20.dylib
    

    Now debugging the same project, the call to open still fails with:

    2018-10-12 08:44:19.696706+0100 SimonQtWidgets[1253:117317] loaded library "/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib"
    2018-10-12 08:44:39.663805+0100 SimonQtWidgets[1253:117317] QSqlError("1130", "QMYSQL: Unable to connect", "Host '192.168.1.158' is not allowed to connect to this MariaDB server")
    2018-10-12 08:44:40.409469+0100 SimonQtWidgets[1253:117317] Failed to connect.
    

    Now resolved, the issue here was that the call to setHostName was using the host name of the system, I changed this to localhost and now everything works.


  • Lifetime Qt Champion

    That shouldn't be necessary but at least it got you going further.

    As for your second error, this is your database configuration you have to inspect.

    Is it a remote machine ? If not then replace the host name with localhost and try again.


Log in to reply