7

When i tried to connect to mysql, there is a error:

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

So i googled it, and i tried :

1.Copy sqldrivers folders to C:\Qt\Qt5.8.0\5.8\mingw53_32\plugins

2.Copy libmysql.dll to C:\Qt\Qt5.8.0\5.8\mingw53_32\bin

but the error is still there.

Is there anything i am missing?

Xi Chen
  • 101
  • 1
  • 2
  • 7
  • "Copy sqldrivers folders to C:\Qt\Qt5.8.0\5.8\mingw53_32\plugins" from where ? the `sqldrivers`folder is already supposed to be in `/plugins` – Benjamin T Mar 09 '17 at 08:46
  • Possible duplicate of [Why QMYSQL driver not loaded in QT5.2?](https://stackoverflow.com/questions/21450861/why-qmysql-driver-not-loaded-in-qt5-2) – Mohammad Kanan Jul 29 '17 at 21:10

6 Answers6

6

There are 64 bit and 32 bit versions of libmysql.dll. rebuilding the Qt Driver is NOT a must.

With the prebuilt version of Qt5.9.1, you still need to use the 32 bit version, it worked even with the 64 version of MySQL installation. without any rebuild of QT plugins or components. Download 32 bit MySQL connector here

This was already answered here: medasumanth answer

Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
  • 2
    Just to make it clear, if you are using a x64 version of Qt, you need to use the x64 connector file. If you are using a x86 version of Qt, you need to use the x86 connector file. Connectors can be downloaded here: https://dev.mysql.com/downloads/connector/c/. Doing so worked for me (both versions of Qt). – gfrigon Oct 12 '17 at 21:05
  • No objection. I have not seen MinGw_64 with Qt installer, but always MinGW32. I am not using MSVC32/64. Does msvc64 need specifically the 64 bit MySQL connector? – Mohammad Kanan Oct 12 '17 at 21:51
5

This error generally means that Qt MySQL plugin is fine (as it is listed in available drivers), but you are a missing the MySQL dll (thus preventing the driver to load).

The way to fix it is to place libmysql.dll somewhere in your PATH, e.g. adding the MySQL installation folder to PATH, or copy libmysql.dll in the same folder you have your exe in.

Benjamin T
  • 8,120
  • 20
  • 37
2

If anyone is stupid as i am so that's for you: What basically you should do is

  1. go to https://downloads.mysql.com/archives/c-c/ and download specifically C !!!!!! MysqlConnector;
  2. place "libmysql.dll" and "libmysql.lib" ("mysql-connector-c-6.1.11-winx64.zip\mysql-connector-c-6.1.11-winx64\lib") into "c:\path_to_qt\qt_version\your_compiler\bin\" for me it looked like "c:\Qt\5.12.1\mingw73_64\bin\";
  3. reload creator and voila your mysql driver is perfectly loaded;

So basically for those who want to understand what happened here:

That "qsqlmysql" plugin is basically a qt interface that uses mysql-C connector methods. But unfortunately this connector does not distributed with Qt, so you should provide it by yourself.

If you want to distribute your software you should copy "libmysql.dll" into the folder with your ".exe" file.

I hope this will help someone save some time (3hours for me :) ).

APetrovsky
  • 31
  • 2
2

It's late to answer, but this may be useful for future readers.

When QMYSQL is available but not loaded, you should find libqsqlmysql.a and libqsqlmysqld.a files corresponding to qsqlmysql.dll and qsqlmysqld.dll files and copy them (.a files) into "\mingw73_xx\lib" folder. (xx means 64 or 32)

Note that for project kit 64 bit use MySql 64 bit, and for project kit 32 bit use MySql 32 bit.

Details are available at QT : QSqlDatabase: QMYSQL driver not loaded [WINDOWS]

Morteza M
  • 130
  • 6
1
  1. You must rebuild mysql driver.
  2. Follow this guide

    Note: you need 3 things:

    a. qt-opensource-xxx-mingw492-xxx.exe for Qt Creator and Qt command Prompt.

    b.qt-everywhere-opensource-src-xxx.zip for Qt source code, needed for mysql.pro file. c.mysql-connector-c-6.1.10-win32.zip needed for lib and include folder.

dante
  • 984
  • 3
  • 10
  • 24
0

I had the same problem. I could solved it by following Benjamin T advise. - Windows 10 - python 3.7 - PyQt5 - I copied the libmysql.dll file from the python 3.7/lib/site-packages folder to the Python 3.7 executable folder and everything started working just fine!

Erick
  • 301
  • 3
  • 12