Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded
Forum Updated to NodeBB v4.3 + New Features

Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded

Scheduled Pinned Locked Moved Solved General and Desktop
40 Posts 5 Posters 9.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #30

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

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #31

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #32

        @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
        

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #33

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by SPlatten
            #34

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

            Kind Regards,
            Sy

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #35

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by SPlatten
                #36

                @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
                

                Kind Regards,
                Sy

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by SGaist
                  #37

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

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by SPlatten
                    #38

                    @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
                    

                    Kind Regards,
                    Sy

                    1 Reply Last reply
                    0
                    • SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by SPlatten
                      #39

                      @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.

                      Kind Regards,
                      Sy

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #40

                        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.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved