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

QMYSQL driver not loaded



  • Hello everyone!
    I am trying to connect my application to a local database, through the MYSQL connector, but the connection not work. I searched the forum and saw that it is a common problem, but I haven't found the solution.

    This is my code:

    83c39a55-5c75-4813-acf3-441a04b27dac-image.png

    Initially the error was:
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7

    Next, I put qsqlmysql.dll into :\Qt\5.14.2\mingw73_32\plugins\sqldrivers, and the error become:
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

    I read that is need put libmysql.dll (32 bit) into :\Qt\5.14.2\mingw73_32\bin

    However this not work for me...



  • Hello! Did you build qsqlmysql.dll yourself?
    And if your libmysql.dll is from MySQL Connector/C 6.1, you'll need VS2015 runtime installed on your machine.



  • In QT Creator go to projects on the left side(wrench) and click on it(make sure your in debug). Then under build/build environment add the variable QT_DEBUG_PLUGINS and set it to 1.

    Then run again and read the plugin trace and see where it is looking for libmysql.dll and put it there. And make sure you do what @Bonnie said.

    --James



  • @JSher

    What is your qt version or which toolkit you are using ?
    And which mysql version you are using ?





  • Can you open your qsqlmysql.dll and libmysql.dll with the dependancy walker to make sure all dependancies are found? In my case the libmysql.dll needed 2 additional dlls (I took it from the MySql Server 8.0).

    If you built the driver yourself and installed is according to the documentation (not only compiling), you should not need to copy the qsqlmysql.dll file to the folder \Qt\5.14.2\mingw73_32\plugins\sqldrivers. It should be done during the installation, if I am not wrong.



  • I had brutally copied qsqlmysql.dll into sqldriver.
    I just built the plugin as explained here (https://doc.qt.io/qt-5/sql-driver.html) and it works perfectly.

    Thank you all



  • @Ketan__Patel__0011 What is your qt version or which toolkit you are using ?
    And which mysql version you are using ?

    I am using 5.9.9 and I do not have mysql(connecting to a remote server), I just downloaded the connector 6.1 I think that has the libs already built.

    --James



  • @JSher

    Copy libmysql.dll into your <QTDIR>bin
    Copy libmysql.dll into this Path : C:\Windows\System32
    Copy libmysql.dll into this Path : C:\Windows

    Set The Environment Variable PATH :

    C:\Program Files\MySQL\MySQL Server 5.6\include

    C:\Program Files\MySQL\MySQL Server 5.6\lib



  • @Bonnie About the deployment I put libmysql.dll (from MySQL Connector / C 6.1) in the folder containing the exe. Does VS2015 runtime need to be installed on each device? To avoid this, can I take the library from other sources?



  • @AndreaCT Yes, you can use older versions that has no dependency on VS runtimes. Just check the dll with dependency walker.
    EDITED
    Actually as I checked, VS runtimes are necessary since 6.1.10.
    I think you can try MySQL Connector/C version 6.1.9 or 6.1.6



  • Perfect, thank you very much


Log in to reply