Cant connect to mysql database: QMYSQL driver not loaded
-
Thank you.
I used /lib because it's in on the instructions on the Qt website: http://doc.qt.io/qt-5/sql-driver.html Can I file a bug report for the instructions on the site?How to Build the QMYSQL Plugin on Windows You need to get the MySQL installation files. Run SETUP.EXE and choose "Custom Install". Install the "Libs & Include Files" Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:\MySQL): cd %QTDIR%\qtbase\src\plugins\sqldrivers qmake -- MYSQL_INCDIR=C:/MySQL/include "MYSQL_LIBDIR=C:/MYSQL/MySQL Server <version>/lib/opt" nmake sub-mysql If you are not using a Microsoft compiler, replace nmake with mingw32-make in the line above.
I'll test your suggestion shortly.
Cheers,
Cedric -
I think you may have misread the documentation.
There are two variables:
MYSQL_INCDIR
andMYSQL_LIBDIR
. -
Hello! Do you have
libs
included in your.pro
file?contains(QMAKE_TARGET.arch, x86_64) { LIBS += -L"C:/MySQL/mysql-5.7.22-winx64/lib" -llibmysql } else { LIBS += -L"C:/MySQL/mysql-5.7.22-win32/lib" -llibmysql }
Note that you need to download the
MySQL
from here MySQL Community Server and extract the data for example toC
drive. Also I suggest to copylibmysql.dll
to the application directory.I use
Qt 5.9.6
andVisual Studio 2017
compiler and it doesn't require to build the driver forMySQL
. -
Hi All,
I'm one step closer to my goal, I can now build the plugin. I cannot yet connect to my database.
Steps I've taken:- Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
- Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path
- Open cmd.exe, and enter the following commands:
c:\Qt\5.10.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1"\lib Running configuration tests... Checking for DB2 (IBM)... no Checking for InterBase... no Checking for MySQL... yes Checking for OCI (Oracle)... no Checking for ODBC... yes Checking for PostgreSQL... no Checking for SQLite (version 2)... no Checking for TDS (Sybase)... no Done running configuration tests. Configure summary: Qt Sql: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. yes OCI (Oracle) ........................... no ODBC ................................... yes PostgreSQL ............................. no SQLite2 ................................ no SQLite ................................. yes Using system provided SQLite ......... no TDS (Sybase) ........................... no Qt is now configured for building. Just run 'mingw32-make'. Once everything is built, Qt is installed. You should NOT run 'mingw32-make install'. Note that this build cannot be deployed to other machines or devices. Prior to reconfiguration, make sure you remove any leftovers from the previous build. mingw32-make <<lots of text>>
- Create a new Qt program, with the following options:
Qt widgets application
Name: sqlTest
Kit: Desktop Qt 5.11.1 MinGB 32 bit (default)
ClassName: (MainWindow) (default)
Version control: Git
QT += core gui sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = sqlTest TEMPLATE = app DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ mainwindow.cpp HEADERS += \ mainwindow.h FORMS += \ mainwindow.ui
mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QtSql> #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("localhost"); db.setDatabaseName("world"); db.setUserName("root"); db.setPassword("PassOlyForForumQuestion"); bool ok = db.open(); qDebug()<<ok; } MainWindow::~MainWindow() { delete ui; }
Program output:
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7 false
Cheers,
Cedric -
Did you install the plugin ?
Did you also check that the
PATH
environment variable in the Run part of the Project panel contains the folder where the MySQL .dlls can be found ? -
Did you install the plugin ?
Did you also check that the
PATH
environment variable in the Run part of the Project panel contains the folder where the MySQL .dlls can be found ?How can I install the plugin? Where can the plugin be found? What does it look like? Where does Qt look for the plugin?
Why does the Qt runtime tell me the QMYSQL driver is available while the driver cannot be loaded? Is there any way to see why the driver did not load?
Is there a guide anywhere that works with the current version of myqsl and the current version of Qt? This guide is for mysql version 5.1: https://forum.qt.io/topic/40672/how-to-create-the-plugin-of-mysql-for-qt
Am I the first one that tries to use Qt 5 and mysql server 8?
Cheers,
Cedric -
It's explained in the documentation
In the plugins subfolder of your Qt installation undersqldrivers
.
It's a .dll file since you're on Windows.
Qt looks for the plugins in the subfolder named plugins unless you tweaked the qt.conf file.Likely because it can find the plugin but will fail to load it. Most of the time it happens because the MySQL .dll files can't be found at run time hence my suggestion in my last post.
The current Qt documentation does.
No you're note, however MySQL server 8 saw a change in their support for their
my_bool
custom type. There's a patch to support build the Qt MySQL plugin with MySQL 8. -
Thanks for your reply.
The documentation you linked (http://doc.qt.io/qt-5/sql-driver.html#building-the-drivers) assumes mysql is installed in c:\mysql. This is not the case for a default installation of mysql8, as it installs itself into c:\program files and c:\program files (x86). This leads me to the conclusion that the install instructions on that page are outdated.
Do you know any instructions for building the plugin for qt5 and mysql 8?
Cheers,
Cedric -
The doc says:
You need to get the MySQL installation files. Run SETUP.EXE and choose "Custom Install". Install the "Libs & Include Files" Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:\MySQL):
This simply means that it assumes that the user selected that folder to install MySQL.
Then:
cd %QTDIR%\qtbase\src\plugins\sqldrivers qmake -- MYSQL_INCDIR=C:/MySQL/include "MYSQL_LIBDIR=C:/MYSQL/MySQL Server <version>/lib/opt" nmake sub-mysql
It shows that the build is configured to use that folder.
If you put MySQL somewhere else, update the command accordingly to use that folder.
-
I have done the steps again:
c:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1"\lib
and
mingw32-makeAfter this, there's no mysql.dll below C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers (in fact, there's no mysql.dll on my entire C:\ drive)
However, this directory is newly created:
C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers
it contains the following files: (and a few extra files with sqlite in the name)
qsqlmysql.dll
qsqlmysqld.dll
qsqlodbc.dll
qsqlodbcd.dllWhere do I put these?
Cheers,
Cedric -
I have done the steps again:
c:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1"\lib
and
mingw32-makeAfter this, there's no mysql.dll below C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers (in fact, there's no mysql.dll on my entire C:\ drive)
However, this directory is newly created:
C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers
it contains the following files: (and a few extra files with sqlite in the name)
qsqlmysql.dll
qsqlmysqld.dll
qsqlodbc.dll
qsqlodbcd.dllWhere do I put these?
Cheers,
Cedric -
Thanks jsulm,
I've just done the mingw32-make install, but my Qt program does not load the driver yet.
I've installed Process monitor (https://docs.microsoft.com/en-us/sysinternals/downloads/procmon) to monitor the syscalls from my application. I've done the following steps with it:
1-run procmon.exe
2-choose filter-reset filter
3-run my program
4-choose tools-process tree
5-select my program, right click, and choose "Add process to include filter" Now only the syscalls from my program are shown.
6)ctrl-f mysql and press F3 a couple of times. Now I see BUFFER OVERFLOW. Can this be a problem?CreateFile C:\Qt\5.10.1\mingw53_32\plugins\sqldrivers\qsqlmysql.dll SUCCESS Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: n/a, OpenResult: Opened QueryInformationVolume C:\Qt\5.10.1\mingw53_32\plugins\sqldrivers\qsqlmysql.dll BUFFER OVERFLOW VolumeCreationTime: 31-01-2018 09:56:48, VolumeSerialNumber: AC0C-32AB, SupportsObjects: True, VolumeLabel: WinÀ
Also, I see my program searches for libmysql.dll in the following paths:
C:\ProgramData\Oracle\Java\javapath_target_378770\LIBMYSQL.DLL C:\Windows\SysWOW64\libmysql.dll C:\Windows\libmysql.dll C:\Windows\SysWOW64\wbem\libmysql.dll C:\Windows\SysWOW64\WindowsPowerShell\v1.0\libmysql.dll C:\Program Files\Git\cmd\libmysql.dll C:\Program Files\TortoiseGit\bin\libmysql.dll C:\Qt\Tools\mingw530_32\bin\libmysql.dll C:\Program Files\PuTTY\libmysql.dll C:\Program Files\MySQL\MySQL Utilities 1.6\libmysql.dll C:\Qt\5.10.1\mingw53_32\bin\libmysql.dll
Mysql.dll is present on my system: C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib, so I copy it into
C:\Qt\Tools\mingw530_32\bin
Now I see libmysql.dll being successfully loaded by my program, and the error message is gone, and after supplying the correct password, I now have a connection into my mysql database.Thank you all for your assistance.
Shall I edit my opening post with the solution, place it below, or make a new post about it?
Cheers,
Cedric -
Thanks jsulm,
I've just done the mingw32-make install, but my Qt program does not load the driver yet.
I've installed Process monitor (https://docs.microsoft.com/en-us/sysinternals/downloads/procmon) to monitor the syscalls from my application. I've done the following steps with it:
1-run procmon.exe
2-choose filter-reset filter
3-run my program
4-choose tools-process tree
5-select my program, right click, and choose "Add process to include filter" Now only the syscalls from my program are shown.
6)ctrl-f mysql and press F3 a couple of times. Now I see BUFFER OVERFLOW. Can this be a problem?CreateFile C:\Qt\5.10.1\mingw53_32\plugins\sqldrivers\qsqlmysql.dll SUCCESS Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: n/a, OpenResult: Opened QueryInformationVolume C:\Qt\5.10.1\mingw53_32\plugins\sqldrivers\qsqlmysql.dll BUFFER OVERFLOW VolumeCreationTime: 31-01-2018 09:56:48, VolumeSerialNumber: AC0C-32AB, SupportsObjects: True, VolumeLabel: WinÀ
Also, I see my program searches for libmysql.dll in the following paths:
C:\ProgramData\Oracle\Java\javapath_target_378770\LIBMYSQL.DLL C:\Windows\SysWOW64\libmysql.dll C:\Windows\libmysql.dll C:\Windows\SysWOW64\wbem\libmysql.dll C:\Windows\SysWOW64\WindowsPowerShell\v1.0\libmysql.dll C:\Program Files\Git\cmd\libmysql.dll C:\Program Files\TortoiseGit\bin\libmysql.dll C:\Qt\Tools\mingw530_32\bin\libmysql.dll C:\Program Files\PuTTY\libmysql.dll C:\Program Files\MySQL\MySQL Utilities 1.6\libmysql.dll C:\Qt\5.10.1\mingw53_32\bin\libmysql.dll
Mysql.dll is present on my system: C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib, so I copy it into
C:\Qt\Tools\mingw530_32\bin
Now I see libmysql.dll being successfully loaded by my program, and the error message is gone, and after supplying the correct password, I now have a connection into my mysql database.Thank you all for your assistance.
Shall I edit my opening post with the solution, place it below, or make a new post about it?
Cheers,
Cedric -
I have done the steps again:
c:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1"\lib
and
mingw32-makeAfter this, there's no mysql.dll below C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers (in fact, there's no mysql.dll on my entire C:\ drive)
However, this directory is newly created:
C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers
it contains the following files: (and a few extra files with sqlite in the name)
qsqlmysql.dll
qsqlmysqld.dll
qsqlodbc.dll
qsqlodbcd.dllWhere do I put these?
Cheers,
Cedric@cdwijs
I'm having trouble to execute these code linesMy cmd input:
D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"mingw32-make sub-mysql
My cmd output:
C:\Users\lucya\Desktop>D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
'D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers' is not recognized as an internal or external command,
operable program or batch file.C:\Users\lucya\Desktop>qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"
Usage: qmake [mode] [options] [files]QMake has two modes, one mode for generating project files based on
some heuristics, and the other for generating makefiles. Normally you
shouldn't need to specify a mode, as makefile generation is the default
mode for qmake, but you may use this to test qmake on an existing projectMode:
-project Put qmake into project file generation mode
In this mode qmake interprets files as files to
be built,
defaults to *; *; *; *.ts; *.xlf; *.qrc
Note: The created .pro file probably will
need to be edited. For example add the QT variable to
specify what modules are required.
-makefile Put qmake into makefile generation mode (default)
In this mode qmake interprets files as project files to
be processed, if skipped qmake will try to find a project
file in your current working directoryWarnings Options:
-Wnone Turn off all warnings; specific ones may be re-enabled by
later -W options
-Wall Turn on all warnings
-Wparser Turn on parser warnings
-Wlogic Turn on logic warnings (on by default)
-Wdeprecated Turn on deprecation warnings (on by default)Options:
- You can place any variable assignment in options and it will be *
- processed as if it was in [files]. These assignments will be *
- processed before [files] by default. *
-o file Write output to file
-d Increase debug level
-t templ Overrides TEMPLATE as templ
-tp prefix Overrides TEMPLATE so that prefix is prefixed into the value
-help This help
-v Version information
-early All subsequent variable assignments will be
parsed right before default_pre.prf
-before All subsequent variable assignments will be
parsed right before [files] (the default)
-after All subsequent variable assignments will be
parsed after [files]
-late All subsequent variable assignments will be
parsed right after default_post.prf
-norecursive Don't do a recursive search
-recursive Do a recursive search
-set <prop> <value> Set persistent property
-unset <prop> Unset persistent property
-query <prop> Query persistent property. Show all if <prop> is empty.
-qtconf file Use file instead of looking for qt.conf
-cache file Use file as cache [makefile mode only]
-spec spec Use spec as QMAKESPEC [makefile mode only]
-nocache Don't use a cache file [makefile mode only]
-nodepend Don't generate dependencies [makefile mode only]
-nomoc Don't generate moc targets [makefile mode only]
-nopwd Don't look for files in pwd [project mode only]
C:\Users\lucya\Desktop>mingw32-make sub-mysql
mingw32-make: *** No rule to make target 'sub-mysql'. Stop. -
@cdwijs
I'm having trouble to execute these code linesMy cmd input:
D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"mingw32-make sub-mysql
My cmd output:
C:\Users\lucya\Desktop>D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
'D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers' is not recognized as an internal or external command,
operable program or batch file.C:\Users\lucya\Desktop>qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"
Usage: qmake [mode] [options] [files]QMake has two modes, one mode for generating project files based on
some heuristics, and the other for generating makefiles. Normally you
shouldn't need to specify a mode, as makefile generation is the default
mode for qmake, but you may use this to test qmake on an existing projectMode:
-project Put qmake into project file generation mode
In this mode qmake interprets files as files to
be built,
defaults to *; *; *; *.ts; *.xlf; *.qrc
Note: The created .pro file probably will
need to be edited. For example add the QT variable to
specify what modules are required.
-makefile Put qmake into makefile generation mode (default)
In this mode qmake interprets files as project files to
be processed, if skipped qmake will try to find a project
file in your current working directoryWarnings Options:
-Wnone Turn off all warnings; specific ones may be re-enabled by
later -W options
-Wall Turn on all warnings
-Wparser Turn on parser warnings
-Wlogic Turn on logic warnings (on by default)
-Wdeprecated Turn on deprecation warnings (on by default)Options:
- You can place any variable assignment in options and it will be *
- processed as if it was in [files]. These assignments will be *
- processed before [files] by default. *
-o file Write output to file
-d Increase debug level
-t templ Overrides TEMPLATE as templ
-tp prefix Overrides TEMPLATE so that prefix is prefixed into the value
-help This help
-v Version information
-early All subsequent variable assignments will be
parsed right before default_pre.prf
-before All subsequent variable assignments will be
parsed right before [files] (the default)
-after All subsequent variable assignments will be
parsed after [files]
-late All subsequent variable assignments will be
parsed right after default_post.prf
-norecursive Don't do a recursive search
-recursive Do a recursive search
-set <prop> <value> Set persistent property
-unset <prop> Unset persistent property
-query <prop> Query persistent property. Show all if <prop> is empty.
-qtconf file Use file instead of looking for qt.conf
-cache file Use file as cache [makefile mode only]
-spec spec Use spec as QMAKESPEC [makefile mode only]
-nocache Don't use a cache file [makefile mode only]
-nodepend Don't generate dependencies [makefile mode only]
-nomoc Don't generate moc targets [makefile mode only]
-nopwd Don't look for files in pwd [project mode only]
C:\Users\lucya\Desktop>mingw32-make sub-mysql
mingw32-make: *** No rule to make target 'sub-mysql'. Stop.@lucaynnofrota said in Cant connect to mysql database: QMYSQL driver not loaded:
D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
This is not a command but a directory!
Please change tocd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
then
qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"
-
@lucaynnofrota said in Cant connect to mysql database: QMYSQL driver not loaded:
D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
This is not a command but a directory!
Please change tocd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
then
qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"
Thanks for reply but I made a mistake. I removed CD on publication. But I have executed the correct code.
-
Thanks for reply but I made a mistake. I removed CD on publication. But I have executed the correct code.
@lucaynnofrota If you get
"'D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers' is not recognized as an internal or external command,
operable program or batch file."
it means that you're trying to execute it. So, are you really sure you didcd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
?
-
@lucaynnofrota If you get
"'D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers' is not recognized as an internal or external command,
operable program or batch file."
it means that you're trying to execute it. So, are you really sure you didcd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
?