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. Unable to connect to MySQL, driver not loaded

Unable to connect to MySQL, driver not loaded

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 2.1k Views
  • 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.
  • D Offline
    D Offline
    DanilZ
    wrote on 23 Jun 2022, 16:22 last edited by
    #1

    Hello to everyone!

    I know this topic had been discussed multiple times, and trust me - I've read them all. My life has stopped for 3 days already since I've been trying to set up my python application to run PyQt6 code with MySQL database connection.

    1. MacOS 12.4 x86
    2. I have installed the latest version of PyQt6 (6.3.1) with $ pip install PyQt6
    3. I have downloaded and installed the MySQL Community Server distribution here https://dev.mysql.com/downloads/mysql
    4. In python I run :
      from PyQt6.QtSql import QSqlDatabase
      db = QSqlDatabase.addDatabase('QMYSQL')
      and I get the following error:
      QSqlDatabase: QMYSQL driver not loaded
      QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
      QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins

    Ok, so the most comprehensive guide on this forum is here:
    https://forum.qt.io/topic/106565/mysql-qt-create-plugin-mysql-for-qt-on-mac

    But I get stuck on the point 3 which redirects to the QT documentation https://doc.qt.io/qt-5/sql-driver.html#qmysql
    which says:
    How to Build the QMYSQL Plugin on Unix and macOS
    cd $QTDIR/qtbase/src/plugins/sqldrivers
    qmake -- MYSQL_PREFIX=/usr/local
    make sub-mysql

    First of all:
    my QTDIR does not contain the /qtbase/srs directories

    Here is my default python package installation path where QT was installed:
    /Users/danil/anaconda3/lib/python3.7/site-packages/PyQt6/Qt6/plugins/sqldrivers
    This folder contains:
    libqsqlite.dylib
    libqsqlodbc.dylib
    libqsqlpsql.dylib

    MySQL is installed in the usr/local/mysql-8.0.29-macos12-x86_64

    Okay, so when I cd to this folder .../sqldrivers and try:
    qmake -- MYSQL_PREFIX=/usr/local/ (tried adding mysql / lib / plugins) - I only get the qmake help menu, and nothing happens

    I have already spent 3 sleepless days trying to figure this out and I think I have exhausted all the possible online resources, including Chinese forums and I'm slowly going crazy. Could anyone help please!

    C 1 Reply Last reply 23 Jun 2022, 16:45
    0
    • D DanilZ
      23 Jun 2022, 16:22

      Hello to everyone!

      I know this topic had been discussed multiple times, and trust me - I've read them all. My life has stopped for 3 days already since I've been trying to set up my python application to run PyQt6 code with MySQL database connection.

      1. MacOS 12.4 x86
      2. I have installed the latest version of PyQt6 (6.3.1) with $ pip install PyQt6
      3. I have downloaded and installed the MySQL Community Server distribution here https://dev.mysql.com/downloads/mysql
      4. In python I run :
        from PyQt6.QtSql import QSqlDatabase
        db = QSqlDatabase.addDatabase('QMYSQL')
        and I get the following error:
        QSqlDatabase: QMYSQL driver not loaded
        QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
        QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins

      Ok, so the most comprehensive guide on this forum is here:
      https://forum.qt.io/topic/106565/mysql-qt-create-plugin-mysql-for-qt-on-mac

      But I get stuck on the point 3 which redirects to the QT documentation https://doc.qt.io/qt-5/sql-driver.html#qmysql
      which says:
      How to Build the QMYSQL Plugin on Unix and macOS
      cd $QTDIR/qtbase/src/plugins/sqldrivers
      qmake -- MYSQL_PREFIX=/usr/local
      make sub-mysql

      First of all:
      my QTDIR does not contain the /qtbase/srs directories

      Here is my default python package installation path where QT was installed:
      /Users/danil/anaconda3/lib/python3.7/site-packages/PyQt6/Qt6/plugins/sqldrivers
      This folder contains:
      libqsqlite.dylib
      libqsqlodbc.dylib
      libqsqlpsql.dylib

      MySQL is installed in the usr/local/mysql-8.0.29-macos12-x86_64

      Okay, so when I cd to this folder .../sqldrivers and try:
      qmake -- MYSQL_PREFIX=/usr/local/ (tried adding mysql / lib / plugins) - I only get the qmake help menu, and nothing happens

      I have already spent 3 sleepless days trying to figure this out and I think I have exhausted all the possible online resources, including Chinese forums and I'm slowly going crazy. Could anyone help please!

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 23 Jun 2022, 16:45 last edited by
      #2

      @DanilZ said in Unable to connect to MySQL, driver not loaded:

      Okay, so when I cd to this folder .../sqldrivers and try:

      Please follow the documentation - you need the qt sources and cmake instead qmake. Really don't understand why every day another one asks exact the same question where we give exact the same answer...

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DanilZ
        wrote on 23 Jun 2022, 17:25 last edited by DanilZ
        #3

        Thank you for reaching out!

        This is the problem. Everyone points to the documentation without any explanation and nowhere there is a comprehensive guide. I have not had the experience in drivers configuration and database management, only learning.

        Your link provides instruction to Compile only a specific sql driver, but the paths to the directories in the code sample do not overlap with my local paths in no way. There are simply no such directories.
        For instance:
        C:\Qt\6.0.0\mingw81_64\bin\qt-cmake -G Ninja C:\Qt\6.0.0\Src\qtbase\src\plugins\sqldrivers -DMySQL_INCLUDE_DIR="C:\mysql-8.0.22-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.22-winx64\lib\libmysql.lib" -DCMAKE_INSTALL_PREFIX="C:\Qt\6.0.0\mingw81_64"

        My Qt directory does not have mingw81_64 as well as bin in any subfolders of QT.
        please refer to the screenshot below

        Screenshot 2022-06-23 at 20.20.07.jpg

        I have tried all the possible directory combinations but it is kinda hard when you don't know what you are doing.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 23 Jun 2022, 17:32 last edited by
          #4

          Again - when you want to compile something you need sources (at least it's the case for me, don't know if someone else can compile code without sources though). So you want to compile the Qt mysql driver you need theses sources. They're provided by your Qt online installer.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DanilZ
            wrote on 23 Jun 2022, 17:35 last edited by
            #5

            That would be a great starting point! But where and what should I be looking for? I have installed Qt via $ pip install PyQt6

            J 1 Reply Last reply 23 Jun 2022, 17:39
            0
            • D DanilZ
              23 Jun 2022, 17:35

              That would be a great starting point! But where and what should I be looking for? I have installed Qt via $ pip install PyQt6

              J Offline
              J Offline
              JonB
              wrote on 23 Jun 2022, 17:39 last edited by
              #6

              @DanilZ
              And I believe that is the problem/not sufficient.

              If you have to build drivers you are going to have to do C++ compilation on source code. I imagine PyQt installation does not provide the sources. You need to get the sources from a Qt installation download.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 23 Jun 2022, 17:40 last edited by Christian Ehrlicher
                #7

                Or use another database like postgresql and blame mysql licensing. :)

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1
                • D Offline
                  D Offline
                  DanilZ
                  wrote on 23 Jun 2022, 18:15 last edited by
                  #8

                  Postgres looks like a good choice since among my available drivers I have QPSQL. But when changing the .addDatabase('QPSQL') I again get the same error:

                  Screenshot 2022-06-23 at 21.14.49.jpg

                  I hope this one would be easier to mitigate?

                  J 1 Reply Last reply 23 Jun 2022, 18:19
                  0
                  • D DanilZ
                    23 Jun 2022, 18:15

                    Postgres looks like a good choice since among my available drivers I have QPSQL. But when changing the .addDatabase('QPSQL') I again get the same error:

                    Screenshot 2022-06-23 at 21.14.49.jpg

                    I hope this one would be easier to mitigate?

                    J Offline
                    J Offline
                    JonB
                    wrote on 23 Jun 2022, 18:19 last edited by
                    #9

                    @DanilZ
                    While you await @Christian-Ehrlicher

                    Enter

                    export QT_DEBUG_PLUGINS=1
                    

                    as a command and then re-run your command. Look through the diagnostic output for a clue as to why QPSQL is available but did not get loaded.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DanilZ
                      wrote on 23 Jun 2022, 19:36 last edited by
                      #10

                      Here is what I've got

                      Screenshot 2022-06-23 at 22.36.24.jpg

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 23 Jun 2022, 19:48 last edited by
                        #11

                        Hi,

                        Did you install the Postgres application ?

                        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
                        • D Offline
                          D Offline
                          DanilZ
                          wrote on 23 Jun 2022, 20:07 last edited by
                          #12

                          That was the problem. Just installed it and now my program is failing at another point. But at least I've got passed the problem of initialising a DB object. Now it seems to be connecting to a database, thanks to you guys!

                          1 Reply Last reply
                          0

                          1/12

                          23 Jun 2022, 16:22

                          • Login

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