Qt World Summit: Register Today!

QMYSQL driver not loaded. Windows x64 deployment.

  • I know there are many topics concerning this stuff but I am new to Qt and to PC software development in general, and I cant seem to get this to work. I'm probably lacking a basic grasp of some things.

    I have written this small console app to write stuff to MySQL database.
    In order to get it to work even on my development PC, I had to compile the database drivers as discussed a lot in topics concerning this matter.

    After that, I used windeployqt to get the dependencies and it gathered them nicely. However, when I copied my app to another 64 bit Windows, the app tells me that

    QSqlDatabase: QMYSQL driver not loaded

    It works on my development machine, so I tried renaming libmysql.dll on my Windows folder to something else to determine if that is the dll the app is using, and it turned out that it was.

    Then I copied that to my target machines Windows folder AND to the folder of my executable at the target machine. This did not do the trick. Why is that? Since both machines are x64 Windows 10 and I have compiled the app using msvc2015_64 in release mode.

    It was not totally clear to me that what I was doing when I was compiling the drivers. If I understood correctly the end result of that was the qsqlmysql.dll file in the sqldrivers folder. So using the lib, dll and the h files in the MySQL server install directory I compiled this driver.

    Edit: This is what I did exactly
    Opened Qt MSVC2015_64 console
    ran C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat
    ran qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"
    ran nmake
    ran nmake install

    Of course the entire sqldrivers folder was copied to the target along with the app and yet it does not work so what gives? Do I somehow have to repeat this process on the target machine?

    To clarify, the database is running on the target machine, but its also installed on the development machine and I used the development machine files in the driver compilation.

    Development OS: Windows 10 Home x64
    Target OS: Windows 10 Enterprice LTSC x64
    Qt version: 5.15.2 MSVC2015 x64
    Qt Creator: 4.14.1
    MySQL server: 8.0.23 x64

  • Lifetime Qt Champion


    Did you forget to deploy the MySQL .dlls and their dependencies along your application ?

  • @SGaist Meaning all the files in my C:\Program Files\MySQL\MySQL Server 8.0\lib directory? Not just libmysql.dll? Or how do I know all the dependencies? I have tried the dependency walker on my exe and I don't quite understand it. It gives me loads of errors on some file that look like that they have something to do with windows, but no files that seem to me be related to mysql. Still the app starts. I should probably take a closer look at the dependency walker.

  • Lifetime Qt Champion

    No, not all files.

    You can use a tool like Dependency Walker or Dependencies to see what is required.

  • I tried the dependency walker and first of all, there are probably around 300 of these API-MS-WIN-CORE****.DLL:s which it says that "Error opening file. The system cannot find the file specified (2)."
    Same thing with files starting with EXT-MS-WIN....

    In addition there are loads of files having the wrong architecture (x86).

    At the top level there is the only thing that I can tell that is related to MySQL is QT5SQL.dll but seems to be OK judging by the icon.

    When I expand it, there is KERNEL32.dll giving me that same warning about the architecture but nothing about MySQL. Under the QT5SQL, there is the same warning about NTDLL.DLL, VCRUNTIME140.DLL, UCRTBASE.DLL

    I compared the results when running the dep walker on the development PC an on the target PC and they are pretty much the same from what I can tell.

    There is just nothing that seems to clearly have something to do with MySQL and so much other stuff. Seems kind of impossible to figure it out from this.

    Maybe Ill post some pictures tomorrow.

  • Lifetime Qt Champion

    Show full paths and only look for dlls from the mysql directory

  • @Jari-Koivuluoma said in QMYSQL driver not loaded. Windows x64 deployment.:

    QMYSQL driver not loaded

    copy "libmysql.dll" to the deployment directory where your application exists.

Log in to reply