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

What is current (2019) recommended process (complete) for building a MySQL Driver for use with Qt on Windows?



  • I'm trying to sift through the many and aging recommendations of how to successfully build a mysql driver for Qt.

    I sorted through the process for MacOS using this post:
    https://forum.qt.io/topic/106565/mysql-qt-create-plugin-mysql-for-qt-on-mac and got things working there. Now I'm on to Windows and I'm stuck.

    Documentation here: https://doc.qt.io/qt-5/sql-driver.html#qmysql
    Seems to indicate using libmysql with embedded server. It would be wonderfully helpful if someone could specific the link for what needs to be installed from Mysql site.

    I'm seeing references from 2016 that state libmysql is being removed in version 8 which is the current version: https://mysqlserverteam.com/mysql-8-0-retiring-support-for-libmysqld/

    Any help appreciated. The documentation, at least to me, seems to be missing key steps. Given the number of queries on this topic, I must not be alone in this camp. I'm new to Qt so that makes life a little more confusing.


  • Lifetime Qt Champion

    Hi,

    What exact error are you getting ?



  • Hi,

    Using Mysql C++ Connector 8 from link https://dev.mysql.com/get/Downloads/Connector-C++/mysql-connector-c++-8.0.17-winx64.msi

    D:\Users\jhankins\Qt\5.13.1\Src\qtbase\src\plugins>cd sqldrivers

    D:\Users\jhankins\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\Connector C++ 8.0\include" "MYSQL_LIBDIR=C:\Program Files\MySQL\Connector C++ 8.0\lib64"

    Running configuration tests...
    Done running configuration tests.

    Configure summary:

    Qt Sql Drivers:
    DB2 (IBM) .............................. no
    InterBase .............................. no
    MySql .................................. no
    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 'nmake'.
    Once everything is built, you must run 'nmake install'.
    Qt will be installed into 'D:\Users\jhankins\Qt\5.13.1\msvc2017_64'.

    Prior to reconfiguration, make sure you remove any leftovers from
    the previous build.

    D:\Users\jhankins\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers>nmake sub-mysql

    Microsoft (R) Program Maintenance Utility Version 14.16.27034.0
    Copyright (C) Microsoft Corporation. All rights reserved.

    NMAKE : fatal error U1073: don't know how to make 'sub-mysql'
    Stop.

    Using commercial install of Qt not built from source.



  • I have also tried Mysql Server 64 bit from:

    https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.17-winx64.zip

    D:\Users\jhankins\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="D:\Users\jhankins\Documents\mysql-8.0.17-winx64\mysql-8.0.17-winx64\include" MYSQL_LIBDIR="D:\Users\jhankins\Documents\mysql-8.0.17-winx64\mysql-8.0.17-winx64\lib"

    Running configuration tests...
    Done running configuration tests.

    Configure summary:

    Qt Sql Drivers:
    DB2 (IBM) .............................. no
    InterBase .............................. no
    MySql .................................. no
    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 'nmake'.
    Once everything is built, you must run 'nmake install'.
    Qt will be installed into 'D:\Users\jhankins\Qt\5.13.1\msvc2017_64'.

    Prior to reconfiguration, make sure you remove any leftovers from
    the previous build.

    D:\Users\jhankins\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers>nmake sub-mysql

    Microsoft (R) Program Maintenance Utility Version 14.16.27034.0
    Copyright (C) Microsoft Corporation. All rights reserved.

    NMAKE : fatal error U1073: don't know how to make 'sub-mysql'
    Stop.


  • Qt Champions 2019

    @james-hankins said in What is current (2019) recommended process (complete) for building a MySQL Driver for use with Qt on Windows?:

    Running configuration tests...
    Done running configuration tests.

    As you can see no config tests a run. This is due to the fact that you already called qmake in there and qmake caches it's results. Therefore you have to delete config.cache and run qmake again. qmake also says it (in imo not very good wording): "Prior to reconfiguration, make sure you remove any leftovers from the previous build."

    Here my output (with the existing config.cache file)

    D:\CraftRoot\download\git\libs\qt5\qtbase\src\plugins\sqldrivers>D:\CraftRoot\build\libs\qt5\qtbase\qt5-dev\bin\qmake.exe --
    
    Running configuration tests...
    Checking for DB2 (IBM)... no
    Checking for InterBase... no
    Checking for MySQL... no
    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 Drivers:
      DB2 (IBM) .............................. no
      InterBase .............................. no
      MySql .................................. no
      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 'nmake'.
    Once everything is built, Qt is installed.
    You should NOT run 'nmake 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.
    
    
    D:\CraftRoot\download\git\libs\qt5\qtbase\src\plugins\sqldrivers>D:\CraftRoot\build\libs\qt5\qtbase\qt5-dev\bin\qmake.exe -- MYSQL_INCDIR=D:/CraftRoot/download/mysql-8.0.17-winx64/include "MYSQL_LIBDIR=D:/CraftRoot/download/mysql-8.0.17-win
    x64/lib"
    
    Running configuration tests...
    Done running configuration tests.
    
    Configure summary:
    
    Qt Sql Drivers:
      DB2 (IBM) .............................. no
      InterBase .............................. no
      MySql .................................. no
      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 'nmake'.
    Once everything is built, Qt is installed.
    You should NOT run 'nmake 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.
    
    
    D:\CraftRoot\download\git\libs\qt5\qtbase\src\plugins\sqldrivers>del config.cache
    
    D:\CraftRoot\download\git\libs\qt5\qtbase\src\plugins\sqldrivers>D:\CraftRoot\build\libs\qt5\qtbase\qt5-dev\bin\qmake.exe -- MYSQL_INCDIR=D:/CraftRoot/download/mysql-8.0.17-winx64/include "MYSQL_LIBDIR=D:/CraftRoot/download/mysql-8.0.17-win
    x64/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 Drivers:
      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 'nmake'.
    Once everything is built, Qt is installed.
    You should NOT run 'nmake 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.
    


  • Thank you. I tried this just now but I seem to not be getting the Qt Sql Drivers summary showing mysql afterwards:

    D:\Users\jhankins\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers>del config.cache
    
    D:\Users\jhankins\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR=D:/Users/jhankins/Documents/mysql-8.0.17-winx64/mysql-8.0.17-winx64/include "MYSQL_LIBDIR=D:/Users/jhankins/Documents/mysql-8.0.17-winx64/mysql-8.0.17-winx64/lib"
    
    Running configuration tests...
    Checking for DB2 (IBM)... no
    Checking for InterBase... no
    Checking for MySQL... no
    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 Drivers:
      DB2 (IBM) .............................. no
      InterBase .............................. no
      MySql .................................. no
      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 'nmake'.
    Once everything is built, you must run 'nmake install'.
    Qt will be installed into 'D:\Users\jhankins\Qt\5.13.1\msvc2017_64'.
    
    Prior to reconfiguration, make sure you remove any leftovers from
    the previous build.
    
    
    D:\Users\jhankins\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers>
    

  • Qt Champions 2019

    You quoted MYSQL_LIBDIR - this is wrong. There is also a config.log where you can take a look what's going wrong.



  • @christian-ehrlicher config.log for the win! Thank you! So the issue was the VS prompt I used was apparently set to x86. Used the VS x64 Native prompt and qmake showed the mysql Yes and subsequently the nmake sub-mysql worked . Thank you very much!


  • Qt Champions 2019

    Nice. Then please mark the topic as solved :)



  • As a follow up on this: I did get the successful build of the plugin and ran nmake install which drops the artifacts into the D:\Users\jhankins\Qt\5.13.1\msvc2017_64\plugins\sqldrivers\ folder. I see them there.

    Do I need to do anything else in the .PRO file to enable other than QT += sql ?

    As when I attempt to connect I'm still getting:

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

    My project is set to Desktop Qt 5.13.1 MSVC2017 64bit.

    Is there some kind of extra step to point the use of libmysql.dll to this plugin like I had to do for MacOS?

    I didn't have to add a unix libs += on my test macOS project. Not real clear how the plugins libs get incorporated into the project.


  • Qt Champions 2019

    You have to make sure that the mysql libraries are found (= are in the same folder as the plugin or in PATH) which doesn't seem to be the case here.



  • I added libmysql.dll into the plugin directory and that seems to have done it. I first tried adding the lib directory into the path but this didn't seem to work.

    Thanks a million. I have been fighting this bugger for too long.



  • @SGaist @Christian-Ehrlicher @James-Hankins I am getting same error. can you tell me where exacly have you added libmysql.dll file? which plugin directory?

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
    ERROR: Adding database failed!
    

  • Qt Champions 2019

    @nn26 said in What is current (2019) recommended process (complete) for building a MySQL Driver for use with Qt on Windows?:

    exacly have you added libmysql.dll file? which plugin directory?

    Since it's a sql plugin I would try to sqldrivers subdir. Or use windeployqt.


Log in to reply