PDA

View Full Version : Qt 5.2 with MySQL- driver not loaded



Baso
4th February 2014, 21:59
Hello there,
I’ve downloaded and installed Qt 5.2 32 bit for android, my machine is windows 8 64bit, I also have visual studio 2012 installed, MySQL 5.6.16 32bit is installed.

I’m trying to connect to a MySQL database, but I always get this error

QSqlDatabse: QMYSQL driver not loaded
QSqlDatabse: available drivers: QSQLIT QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

Here is my code

#include <QCoreApplication>
#include <QtSql>
#include <QtDebug>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
return a.exec();
}
I’ve known that in Qt 5.2 there is no need to build the driver, anyway I’v tried and built it but with no difference, I don’t know if the built process went well or no.
Any suggestions please because I spent the last two days searching the net for a solution.
Thanks

sakya
4th February 2014, 23:02
I had a similar problem with the PostgreSQL driver on Windows (which, as the mysql driver, is present in the plugins directory and there's no need to build it).
The problem was not the driver but a PostgreSQL dll. Probably it's the same problem with MySQL.
Try to use depends (http://www.dependencywalker.com/) to check what dlls the plugin needs (qsqlmysql.dll) and copy them to your build directory (or add in your PATH the directory containing them).

ChrisW67
5th February 2014, 00:08
The Qt plugins for MySQL/PostgreSQL/ODBC are shipped in the binary download (because too many people were unable to grasp building them) but the Mysql/PostgreSQL/ODBC client libraries/drivers are not bundled.

You need to install at least the MySql Connector: http://dev.mysql.com/downloads/connector/c/

Baso
5th February 2014, 11:32
@sakya I don't know which file to check with dependency walker.

I found the file qsqlmysql.dll in these directories
C:\Qt\Qt5.2.0\Tools\QtCreator\bin\plugins\sqldrive rs
C:\Qt\Qt5.2.0\5.2.0\mingw48_32\plugins\sqldrivers
C:\Qt\Qt5.2.0\5.2.0\mingw48_32\plugins\sqldrivers
and I added them to the environment PATH, I still have the same error

@ChrisW67 I downloaded and installed the connector, but with no hope

sakya
5th February 2014, 13:05
@sakya I don't know which file to check with dependency walker.
The mysql plugin dll is qsqlmysql.dll

The only mysql dependency should be LIBMYSQL.DLL

Baso
5th February 2014, 16:47
I found the file qsqlmysql.dll in this path C:\Qt\Qt5.2.0\5.2.0\mingw48_32\plugins\sqldrivers and I run dependacy walker on it and here is a photo of what I got
10019

any tips?

ChrisW67
5th February 2014, 20:22
Put the Mysql runtime library (libmysql.dll) on the runtime PATH for the process or system PATH... Just like any other DLL the program has to be able to find it to use it.
http://msdn.microsoft.com/en-us/library/7d83bc18.aspx

Baso
5th February 2014, 22:40
Well the path C:\Program Files\MySQL\MySQL Server 5.6\lib which include the libmysql.dll is already in the system PATH !

Willi
6th February 2014, 07:19
You have to install the 32-bit MySQL-ODBC-Driver

Baso
6th February 2014, 08:30
@Willi already installed :(

Baso
6th February 2014, 11:48
<SOLVED> the problem was that I downloaded the offline MySQL installer for windows(x86-32bit) the installer is 32bit, but the server combined with it was (5.6 64bit) looks like there is no 5.6 server 32bit so I installed the 5.5 32bit server instead and it worked.

Thank you all for your help.

deepal_de
6th February 2016, 16:53
Since this is the first thread that comes up in google when you search for "MySQL- driver not loaded" error

update on this when it comes to mysql 5.7.10
the mysql 32 bit installation will install and leave you a x64 dll. this will not work with qt 32 bit qtmysql plugin

you do not need to build Qt mysql plugin since its already there when you install (tested with qt 5.5 : Qt\Qt5.5.0\5.5\[compiler]\plugins\sqldrivers)

what you need to do is install the mysql C connector ( not the C++ one) .
This will give you a libmysql.dll inside you connector lib path (C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib)

use this dll with qsqlmysqld.dll that you already have inside the Qt folder.