/qt_mysql_driver

Typical symptom: QMYSQL driver not loaded. Solution: get pre-built Qt SQL driver plug-in required to establish a connection to MySQL / MariaDB using Qt. Download qsqlmysql.dll binaries built from official Qt source code

OtherNOASSERTION

Typical symptom when trying to connect to MySQL / MariaDB using Qt but without the necessary plugin is the runtime error


 QSqlDatabase: QMYSQL driver not loaded
 QSqlDatabase: available drivers: QMYSQL

Since the Qt Company cannot provide qsqlmysql.dll / libqsqlmysql.so in binary form, you have to build it on your own, which can be a pain. Here is a build for various Qt versions. Get precompiled qsqlmysql.dll for Windows / libqsqlmysql.so for Linux from releases. Be sure to match your Qt version and compiler (Microsoft Visual C++/MSVC, MinGW) EXACTLY. For example if you use Qt 6.4.2, you cannot use driver version 6.4.1 or 6.4.3

This is helpful to you? If you wish, you have the possibility to support me by donating here. Thank you so much everyone who has donated so far

Latest Qt6 version: Download for Qt 6.8.0 here
For Android see 3rd party repository https://github.com/sayyyed/qt_android_mysql_driver/releases/tag/qt_mysql_driver_for_android

Deployment

  1. copy qsqlmysql.dll (release build) / MSVC: qsqlmysqld.dll, MinGW: qsqlmysql.dll+qsqlmysql.debug (debug build) to subdirectory "sqldrivers" of application directory (or build directory while developing)
  1. copy libmysql.dll (MySQL library) and the libcrypto/libssl OpenSSL libraries from zip file (or from https://dev.mysql.com and https://kb.firedaemon.com/support/solutions/articles/4000121705 respectively) to application directory (or more generally, any directory that is registered in PATH environment variable)

Building from source (Qt6/CMake)

Windows
for MSVC:

Prerequisites:

  1. Install MSVC Compiler (C++ Desktop Toolkit from Visual Studio 2022 Setup)
  2. Install Qt incl. Sources, CMake and Ninja from Maintenance Tool
  3. Install MySQL library, e.g. by using Oracle's Installer or use the zip file from here
set PATH=%PATH%;C:\Qt\Tools\CMake_64\bin;C:\Qt\Tools\Ninja
C:
cd C:\Qt\6.6.0\Src\qtbase\src\plugins\sqldrivers
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
call C:\Qt\6.6.0\msvc2019_64\bin\qt-cmake.bat -G "Ninja Multi-Config" . -DMySQL_INCLUDE_DIR="E:\qt_creator\libs\libmysql\include" -DMySQL_LIBRARY="E:\qt_creator\libs\libmysql\lib\libmysql.lib" -DCMAKE_INSTALL_PREFIX="C:\Qt\6.6.0\msvc2019_64" -DCMAKE_CONFIGURATION_TYPES=Release;Debug
ninja
ninja install
pause

for MinGW:

Prerequisites:

  1. Install Qt incl. Sources, CMake and MinGW from Maintenance Tool
  2. Install MySQL library, e.g. by using Oracle's Installer or use the zip file from here
set PATH=%PATH%;C:\Qt\Tools\mingw1120_64\bin;C:\Qt\Tools\CMake_64\bin
cd C:\Qt\6.4.0\Src\qtbase\src\plugins\sqldrivers
call C:\Qt\6.4.0\mingw_64\bin\qt-cmake.bat -G "MinGW Makefiles" . -DMySQL_INCLUDE_DIR="C:\mysql_8.0.29\include" -DMySQL_LIBRARY="C:\mysql_8.0.29\lib\libmysql.lib" -DCMAKE_INSTALL_PREFIX="C:\Qt\6.4.0\mingw_64" -DCMAKE_C_COMPILER="gcc.exe" -DCMAKE_CXX_COMPILER="g++.exe"
mingw32-make
mingw32-make install
pause