huaxz1986
huaxz1986

Reputation: 135

Why QMYSQL driver not loaded in QT5.2?

My program is write with QT5.2 and use mysql. I heared that QT5.2 contains MYSQL driver already. However, when I compile and run my program, it is compiled successfully but runned failed with error:

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

My programe is like this:

     QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
     db.setHostName("localhost");
     db.setDatabaseName("tradingsystem");
     db.setUserName("root");
     db.setPassword("");
     if(!db.open())
     {
          //.....;
     }

And in .pro I add this:

    QT += sql

Mysql is provided by XAMPP.My OS is win7-x64-sp1-ultimate, and XAMPP Version 1.8.2.System Path is as follow:

    C:\Program Files (x86)\SepanderSoft;
    C:\Program Files (x86)\Intel\iCLS Client\;
    C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
    C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
    C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;
    C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
    C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;
    C:\Program Files\Intel\WiFi\bin\;
    C:\Program Files\Common Files\Intel\WirelessCommon\;
    C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;
    C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;
    C:\Program Files\Microsoft\Web Platform Installer\;
    C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;
    C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;
    C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;
    D:\Software\MySQL\MySQL Enterprise Backup 3.8.2\

XAMPP location is :

    D:\XAMPP

QT location is:

    D:\Software\Qt

I have installed mysql server-5.6-64bit in D:\Software\MySQL, and when it conflicted with mysql in XAMPP, I uninstalled mysql server-5.6-64bit.

Upvotes: 8

Views: 13202

Answers (6)

Necr1s
Necr1s

Reputation: 1

I ran into this issue on a testing enviroment, where there are no developer tools installed. The libmysql.dll was correctly deployed next to the application, but the error was the same.

After hours of googling and trying out possible solutions, I found a post where somebody mentioned that he used the Dependency Walker on the DLL. I followed this advice and it turned out, that it was missing the MSVCR120.dll, which comes with VCRedist 12.0 for Visual Studio 2013. The installation of VCRedist 12.0 solved the issue for me.

Unfortunatly I can't tell from which package the libmysql.dll came from, since I took it from our company third party library. So the requirements for the VCRedist version may vary in different versions of the DLL.

Upvotes: 0

Sam Highfield
Sam Highfield

Reputation: 11

I also spent about 2 days on this problem, here's how I solved it:

My setup: 64 bit Windows 10 QT 5.11.1 and QT Creator 4.7.1 32 bit Building a 64 bit app...

Download this zip file: mysql-connector-c-6.1.11-winx64.zip from this website: https://downloads.mysql.com/archives/c-c/

copy this file: C:..\mysql-connector-c-6.1.11-winx64.zip\mysql-connector-c-6.1.11-winx64\lib\libmysql.dll

into this directory: C:\Qt\5.11.1\msvc2015_64\bin

Note: change 'msvc2015_64' to whatever compiler you are using, though it needs to be 64 bit.

when deploying your app, copy libmysql.dll to the same directory as your .exe file I hope this helps you same some time and frustration!

Upvotes: 1

Nagaraj Gaonkar
Nagaraj Gaonkar

Reputation: 11

I faced the same issue and resolved by below steps.

By doing 6 hours of research finally issue is resolved. I was using 64 bit windows 10, 32 bit Qta and 64 bit MySQL server.

QSQLITE and QODBC was working perfectly, but faced issue with QMYSQL.

Later I have downloaded "mysql-connector-c-6.1.11-win32.zip" (if it is 32 bit QT)from https://dev.mysql.com/downloads/connector/c/ copied "libmysql.dll" to QT path C:\Qt\5.9.3\mingw53_32\bin.

Wow.. it was working perfectly.

Upvotes: 1

Jeramy D.
Jeramy D.

Reputation: 53

Adding post due to reputation deficit.

I was able to resolve my issue using a combination of Hồ Sĩ Sơn, Ram, and Sumanth's posts (Thank you both).

Here are my exact steps:

Checked the version of Qt Creator that I am running by visiting Help -> About Qt Creator. I found that I am running the 32-bit version.

Now that I know what version I am running I navigated to the 32-bit version of the MySQL connector. This was found in C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib.

I copied the libmysql.dll file found in that folder, and pasted it into C:\Qt\5.9.2\mingw53_32\bin\ since I am compiling with MinGW. Note that this is the 32-bit folder.

Restarted Qt Creator and rebuilt my project.

The steps that were challenging me were matching the x-bit version of Qt Creator, my compiler, and the driver, then restarting Qt Creator.

Hope this helps someone out there!

Upvotes: 3

medasumanth
medasumanth

Reputation: 381

I was facing the same issue and even "Hồ Sĩ Sơn"s solution didn't work. I then found out that I had installed a 64-bit version of MySQL and was trying it on a 32-bit version of Qt.

Copying the dll from the below location didn't work:

C:\Program Files\MySQL\MySQL Connector.C 6.1\lib\libmysql.dll

Instead download the 32-bit version of libmysql.dll from:

https://dev.mysql.com/downloads/connector/c/

and the copy it to your mingw folder.

In my case, I had to copy the DLL to msvc2010 folder since I am using Visual Studio compiler:

C:\Qt\5.4\msvc2010_opengl\bin

Hope this helps. :)

Upvotes: 5

Hồ Sĩ Sơn
Hồ Sĩ Sơn

Reputation: 89

I met with the same error and fixed it successfully by copying file

C:\Program Files (x86)\MySQL\MySQL Connector.C 6.1\lib\libmysql.dll

into to

C:\Qt\Qt5.3.1\5.3\mingw482_32\bin

Youtube link

Upvotes: 8

Related Questions