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. Cant connect to mysql database: QMYSQL driver not loaded
Forum Updated to NodeBB v4.3 + New Features

Cant connect to mysql database: QMYSQL driver not loaded

Scheduled Pinned Locked Moved Solved General and Desktop
46 Posts 12 Posters 52.0k Views 4 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.
  • R realmodus

    Does anyone succeed with MySQL and Qt under Windows? I believe that nobody reaches the DB. So! no MySQL connection with Qt? Those who give their help didn't really try, I wonder.

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by
    #31

    @realmodus
    No idea what you're talking about.

    @jsulm
    Your

    cd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers

    I suspect this didn't work for OP as it needs to be cd /d D:\... to make the D: drive the current drive for the subsequent qmake command to be on the right drive, else it'll still be on C:?

    jsulmJ 1 Reply Last reply
    3
    • JonBJ JonB

      @realmodus
      No idea what you're talking about.

      @jsulm
      Your

      cd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers

      I suspect this didn't work for OP as it needs to be cd /d D:\... to make the D: drive the current drive for the subsequent qmake command to be on the right drive, else it'll still be on C:?

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

      @JonB You're right I didn't think about the drive

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

      1 Reply Last reply
      1
      • F Offline
        F Offline
        fyang
        wrote on last edited by
        #33

        we had the same driver nod loaded issue. we fixed by switch compiler as 32bit from originally 64bit to compile application in Qt. Hope this help. some of our machine is 32bit machine.

        1 Reply Last reply
        0
        • C cdwijs

          Hi All,

          I'm one step closer to my goal, I can now build the plugin. I cannot yet connect to my database.
          Steps I've taken:

          1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
          2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path
          3. Open cmd.exe, and enter the following commands:
          c:\Qt\5.10.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1"\lib
          
          Running configuration tests...
          Checking for DB2 (IBM)... no
          Checking for InterBase... no
          Checking for MySQL... yes
          Checking for OCI (Oracle)... no
          Checking for ODBC... yes
          Checking for PostgreSQL... no
          Checking for SQLite (version 2)... no
          Checking for TDS (Sybase)... no
          Done running configuration tests.
          
          Configure summary:
          
          Qt Sql:
            DB2 (IBM) .............................. no
            InterBase .............................. no
            MySql .................................. yes
            OCI (Oracle) ........................... no
            ODBC ................................... yes
            PostgreSQL ............................. no
            SQLite2 ................................ no
            SQLite ................................. yes
              Using system provided SQLite ......... no
            TDS (Sybase) ........................... no
          
          Qt is now configured for building. Just run 'mingw32-make'.
          Once everything is built, Qt is installed.
          You should NOT run 'mingw32-make install'.
          Note that this build cannot be deployed to other machines or devices.
          
          Prior to reconfiguration, make sure you remove any leftovers from
          the previous build.
          
          mingw32-make
          
          <<lots of text>>
          
          1. Create a new Qt program, with the following options:
            Qt widgets application
            Name: sqlTest
            Kit: Desktop Qt 5.11.1 MinGB 32 bit (default)
            ClassName: (MainWindow) (default)
            Version control: Git

          mysql.pro

          QT       += core gui sql
          greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
          TARGET = sqlTest
          TEMPLATE = app
          DEFINES += QT_DEPRECATED_WARNINGS
          SOURCES += \
                  main.cpp \
                  mainwindow.cpp
          HEADERS += \
                  mainwindow.h
          FORMS += \
                  mainwindow.ui
          

          mainwindow.cpp

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          #include <QtSql>
          #include <QDebug>
          MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
          
              QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
             db.setHostName("localhost");
             db.setDatabaseName("world");
             db.setUserName("root");
             db.setPassword("PassOlyForForumQuestion");
             bool ok = db.open();
             qDebug()<<ok;
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          

          Program output:

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

          Cheers,
          Cedric

          H Offline
          H Offline
          Heman
          wrote on last edited by
          #34

          @cdwijs I wish to information you that I have been following the steps you took to build QMySQL driver for Qt 5.13.0 though. However, I got lost at the point you gave three (3) steps you took to get qmake identify mysql driver because at that point my qmake could not identify the driver:

          1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi

          2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path

          3. Open cmd.exe, and enter the following commands:

          4. Are there some other things you did which, perhaps, you did not mention on the steps?

          5. In step 2 of your procedure, you said you added C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path. Did you mean path of system variable?

          I installed MySQL 8.016 community edition and used the same c++ connector, 6.1 32-bit you used.

          Followings are the commands I used but qmake could detect MySQL source driver:
          cd C:\Qt\Qt5.13.0\5.13.0\Src\qtbase\src\plugins\sqldrivers
          qmake -- MYSQL_INCDIR=C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\include "MYSQL_LIBDIR=C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\lib\opt"

          Can you help where I got it wrong?

          Cheers,

          Heman.

          jsulmJ 1 Reply Last reply
          0
          • H Heman

            @cdwijs I wish to information you that I have been following the steps you took to build QMySQL driver for Qt 5.13.0 though. However, I got lost at the point you gave three (3) steps you took to get qmake identify mysql driver because at that point my qmake could not identify the driver:

            1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi

            2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path

            3. Open cmd.exe, and enter the following commands:

            4. Are there some other things you did which, perhaps, you did not mention on the steps?

            5. In step 2 of your procedure, you said you added C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path. Did you mean path of system variable?

            I installed MySQL 8.016 community edition and used the same c++ connector, 6.1 32-bit you used.

            Followings are the commands I used but qmake could detect MySQL source driver:
            cd C:\Qt\Qt5.13.0\5.13.0\Src\qtbase\src\plugins\sqldrivers
            qmake -- MYSQL_INCDIR=C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\include "MYSQL_LIBDIR=C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\lib\opt"

            Can you help where I got it wrong?

            Cheers,

            Heman.

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

            @heman said in Cant connect to mysql database: QMYSQL driver not loaded:

            Are there some other things you did which, perhaps, you did not mention on the steps?

            "mingww32-make install" after successful build is missing.

            You should not set your PATH globally, do it in the cmd.exe window where you build.
            These paths looks strange:
            "C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\include "MYSQL_LIBDIR=C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\lib\opt""
            Use complete paths with escaped spaces. Even better would be to install MySQL stuff in a directory without spaces.

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

            1 Reply Last reply
            2
            • H Offline
              H Offline
              Heman
              wrote on last edited by
              #36

              I get it now. It works.
              I might have included some kind of atrocities who knows? However, these are the steps I took:

              1. I installed MySQL community edition
              2. I installed mysql connector c 6.1
              3. I created a .bat file with the following commands: C:\Windows\System32\cmd.exe /E:ON /V:ON /K C:\Qt\Qt5.13.0\5.13.0\mingw73_32\bin\qmake.exe
                SET _ROOT=C:\Qt\Qt5.13.0
                SET PATH=C:\Qt\Qt5.13.0\5.13.0\mingw73_32\bin;C:\Qt\Qt5.13.0\Tools\mingw730_32\bin;%PATH%
              4. I run cd C:\Qt\Qt5.13.0\5.13.0\Src\qtbase\src\plugins\sqldrivers
              5. I run qmake -- MYSQL_INCDIR="C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib"
                mingw32-make
                ming32-make install
              6. And lastly, I copied libmysql.dll from C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib to C:\Qt\Qt5.13.0\Tools\mingw730_32\bin
              1 Reply Last reply
              0
              • C cdwijs

                Hi All,

                I'm one step closer to my goal, I can now build the plugin. I cannot yet connect to my database.
                Steps I've taken:

                1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
                2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path
                3. Open cmd.exe, and enter the following commands:
                c:\Qt\5.10.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1"\lib
                
                Running configuration tests...
                Checking for DB2 (IBM)... no
                Checking for InterBase... no
                Checking for MySQL... yes
                Checking for OCI (Oracle)... no
                Checking for ODBC... yes
                Checking for PostgreSQL... no
                Checking for SQLite (version 2)... no
                Checking for TDS (Sybase)... no
                Done running configuration tests.
                
                Configure summary:
                
                Qt Sql:
                  DB2 (IBM) .............................. no
                  InterBase .............................. no
                  MySql .................................. yes
                  OCI (Oracle) ........................... no
                  ODBC ................................... yes
                  PostgreSQL ............................. no
                  SQLite2 ................................ no
                  SQLite ................................. yes
                    Using system provided SQLite ......... no
                  TDS (Sybase) ........................... no
                
                Qt is now configured for building. Just run 'mingw32-make'.
                Once everything is built, Qt is installed.
                You should NOT run 'mingw32-make install'.
                Note that this build cannot be deployed to other machines or devices.
                
                Prior to reconfiguration, make sure you remove any leftovers from
                the previous build.
                
                mingw32-make
                
                <<lots of text>>
                
                1. Create a new Qt program, with the following options:
                  Qt widgets application
                  Name: sqlTest
                  Kit: Desktop Qt 5.11.1 MinGB 32 bit (default)
                  ClassName: (MainWindow) (default)
                  Version control: Git

                mysql.pro

                QT       += core gui sql
                greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                TARGET = sqlTest
                TEMPLATE = app
                DEFINES += QT_DEPRECATED_WARNINGS
                SOURCES += \
                        main.cpp \
                        mainwindow.cpp
                HEADERS += \
                        mainwindow.h
                FORMS += \
                        mainwindow.ui
                

                mainwindow.cpp

                #include "mainwindow.h"
                #include "ui_mainwindow.h"
                #include <QtSql>
                #include <QDebug>
                MainWindow::MainWindow(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::MainWindow)
                {
                    ui->setupUi(this);
                
                    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
                   db.setHostName("localhost");
                   db.setDatabaseName("world");
                   db.setUserName("root");
                   db.setPassword("PassOlyForForumQuestion");
                   bool ok = db.open();
                   qDebug()<<ok;
                }
                
                MainWindow::~MainWindow()
                {
                    delete ui;
                }
                

                Program output:

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

                Cheers,
                Cedric

                H Offline
                H Offline
                hobbyProgrammer
                wrote on last edited by
                #37

                @cdwijs said in Cant connect to mysql database: QMYSQL driver not loaded:

                Hi All,

                I'm one step closer to my goal, I can now build the plugin. I cannot yet connect to my database.
                Steps I've taken:

                1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
                2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path

                Hi,
                I am struggling with the same issue, where exactly did you add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to?

                C 1 Reply Last reply
                0
                • H hobbyProgrammer

                  @cdwijs said in Cant connect to mysql database: QMYSQL driver not loaded:

                  Hi All,

                  I'm one step closer to my goal, I can now build the plugin. I cannot yet connect to my database.
                  Steps I've taken:

                  1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
                  2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path

                  Hi,
                  I am struggling with the same issue, where exactly did you add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to?

                  C Offline
                  C Offline
                  cdwijs
                  wrote on last edited by
                  #38

                  @hobbyProgrammer I've added them to the PATH. On widows7, you can find that setting here:
                  start->control panel->system and security->system->Advanced system settings->Advanced->Environment Variables->System variables->Path->Edit...

                  You can see the current value of the path variable by start->run->cmd and the command:
                  echo %PATH%

                  H 1 Reply Last reply
                  0
                  • C cdwijs

                    @hobbyProgrammer I've added them to the PATH. On widows7, you can find that setting here:
                    start->control panel->system and security->system->Advanced system settings->Advanced->Environment Variables->System variables->Path->Edit...

                    You can see the current value of the path variable by start->run->cmd and the command:
                    echo %PATH%

                    H Offline
                    H Offline
                    hobbyProgrammer
                    wrote on last edited by
                    #39

                    @cdwijs thanks, but unfortunately it didn't work for me :(

                    jsulmJ 1 Reply Last reply
                    0
                    • H hobbyProgrammer

                      @cdwijs thanks, but unfortunately it didn't work for me :(

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

                      @hobbyProgrammer Did you log out and log in after changing PATH?

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

                      H 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @hobbyProgrammer Did you log out and log in after changing PATH?

                        H Offline
                        H Offline
                        hobbyProgrammer
                        wrote on last edited by
                        #41

                        @jsulm open the cmd again or log out as a computer user?

                        jsulmJ JonBJ 2 Replies Last reply
                        0
                        • H hobbyProgrammer

                          @jsulm open the cmd again or log out as a computer user?

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

                          @hobbyProgrammer Log out as user and login again, then check in terminal as @cdwijs suggested.

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

                          1 Reply Last reply
                          2
                          • H hobbyProgrammer

                            @jsulm open the cmd again or log out as a computer user?

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #43

                            @hobbyProgrammer
                            In the time it takes to wait for an answer, and in order to be simply confident everything sees the new environment variable, isn't it just quicker to completely log out & in or even reboot and then you know for sure where you are?!

                            1 Reply Last reply
                            1
                            • H Offline
                              H Offline
                              hobbyProgrammer
                              wrote on last edited by
                              #44
                              This post is deleted!
                              1 Reply Last reply
                              0
                              • B Offline
                                B Offline
                                Back2coding
                                wrote on last edited by
                                #45

                                Hello,

                                I have gone through the same issue. there are 2 libmysql.dll libraries version. One for 32 and the other for 64 bits.

                                These 2 files are both available inhere :
                                https://www.dll-files.com/libmysql.dll.html

                                I advise you to do the following.

                                • create a folder in the C drive and name it as you wish and set the PATH to include that folder.

                                • Step number 2, reload your system.

                                • Step number 3 copy one of the 2 files libmysql.dll in that folder and try to run your binary if this doesnt work then try the second one.

                                This should work!

                                have a good day!

                                SGaistS 1 Reply Last reply
                                -1
                                • B Back2coding

                                  Hello,

                                  I have gone through the same issue. there are 2 libmysql.dll libraries version. One for 32 and the other for 64 bits.

                                  These 2 files are both available inhere :
                                  https://www.dll-files.com/libmysql.dll.html

                                  I advise you to do the following.

                                  • create a folder in the C drive and name it as you wish and set the PATH to include that folder.

                                  • Step number 2, reload your system.

                                  • Step number 3 copy one of the 2 files libmysql.dll in that folder and try to run your binary if this doesnt work then try the second one.

                                  This should work!

                                  have a good day!

                                  SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #46

                                  @Back2coding downloading .dlls from 3rd party website like that is usually a bad idea. You do not know what might lurk in there.

                                  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
                                  3

                                  • Login

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