Unable to connect to MySQL, driver not loaded
-
wrote on 23 Jun 2022, 16:22 last edited by
Hello to everyone!
I know this topic had been discussed multiple times, and trust me - I've read them all. My life has stopped for 3 days already since I've been trying to set up my python application to run PyQt6 code with MySQL database connection.
- MacOS 12.4 x86
- I have installed the latest version of PyQt6 (6.3.1) with $ pip install PyQt6
- I have downloaded and installed the MySQL Community Server distribution here https://dev.mysql.com/downloads/mysql
- In python I run :
from PyQt6.QtSql import QSqlDatabase
db = QSqlDatabase.addDatabase('QMYSQL')
and I get the following error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
Ok, so the most comprehensive guide on this forum is here:
https://forum.qt.io/topic/106565/mysql-qt-create-plugin-mysql-for-qt-on-macBut I get stuck on the point 3 which redirects to the QT documentation https://doc.qt.io/qt-5/sql-driver.html#qmysql
which says:
How to Build the QMYSQL Plugin on Unix and macOS
cd $QTDIR/qtbase/src/plugins/sqldrivers
qmake -- MYSQL_PREFIX=/usr/local
make sub-mysqlFirst of all:
my QTDIR does not contain the /qtbase/srs directoriesHere is my default python package installation path where QT was installed:
/Users/danil/anaconda3/lib/python3.7/site-packages/PyQt6/Qt6/plugins/sqldrivers
This folder contains:
libqsqlite.dylib
libqsqlodbc.dylib
libqsqlpsql.dylibMySQL is installed in the usr/local/mysql-8.0.29-macos12-x86_64
Okay, so when I cd to this folder .../sqldrivers and try:
qmake -- MYSQL_PREFIX=/usr/local/ (tried adding mysql / lib / plugins) - I only get the qmake help menu, and nothing happensI have already spent 3 sleepless days trying to figure this out and I think I have exhausted all the possible online resources, including Chinese forums and I'm slowly going crazy. Could anyone help please!
-
Hello to everyone!
I know this topic had been discussed multiple times, and trust me - I've read them all. My life has stopped for 3 days already since I've been trying to set up my python application to run PyQt6 code with MySQL database connection.
- MacOS 12.4 x86
- I have installed the latest version of PyQt6 (6.3.1) with $ pip install PyQt6
- I have downloaded and installed the MySQL Community Server distribution here https://dev.mysql.com/downloads/mysql
- In python I run :
from PyQt6.QtSql import QSqlDatabase
db = QSqlDatabase.addDatabase('QMYSQL')
and I get the following error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
Ok, so the most comprehensive guide on this forum is here:
https://forum.qt.io/topic/106565/mysql-qt-create-plugin-mysql-for-qt-on-macBut I get stuck on the point 3 which redirects to the QT documentation https://doc.qt.io/qt-5/sql-driver.html#qmysql
which says:
How to Build the QMYSQL Plugin on Unix and macOS
cd $QTDIR/qtbase/src/plugins/sqldrivers
qmake -- MYSQL_PREFIX=/usr/local
make sub-mysqlFirst of all:
my QTDIR does not contain the /qtbase/srs directoriesHere is my default python package installation path where QT was installed:
/Users/danil/anaconda3/lib/python3.7/site-packages/PyQt6/Qt6/plugins/sqldrivers
This folder contains:
libqsqlite.dylib
libqsqlodbc.dylib
libqsqlpsql.dylibMySQL is installed in the usr/local/mysql-8.0.29-macos12-x86_64
Okay, so when I cd to this folder .../sqldrivers and try:
qmake -- MYSQL_PREFIX=/usr/local/ (tried adding mysql / lib / plugins) - I only get the qmake help menu, and nothing happensI have already spent 3 sleepless days trying to figure this out and I think I have exhausted all the possible online resources, including Chinese forums and I'm slowly going crazy. Could anyone help please!
@DanilZ said in Unable to connect to MySQL, driver not loaded:
Okay, so when I cd to this folder .../sqldrivers and try:
Please follow the documentation - you need the qt sources and cmake instead qmake. Really don't understand why every day another one asks exact the same question where we give exact the same answer...
-
wrote on 23 Jun 2022, 17:25 last edited by DanilZ
Thank you for reaching out!
This is the problem. Everyone points to the documentation without any explanation and nowhere there is a comprehensive guide. I have not had the experience in drivers configuration and database management, only learning.
Your link provides instruction to Compile only a specific sql driver, but the paths to the directories in the code sample do not overlap with my local paths in no way. There are simply no such directories.
For instance:
C:\Qt\6.0.0\mingw81_64\bin\qt-cmake -G Ninja C:\Qt\6.0.0\Src\qtbase\src\plugins\sqldrivers -DMySQL_INCLUDE_DIR="C:\mysql-8.0.22-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.22-winx64\lib\libmysql.lib" -DCMAKE_INSTALL_PREFIX="C:\Qt\6.0.0\mingw81_64"My Qt directory does not have mingw81_64 as well as bin in any subfolders of QT.
please refer to the screenshot belowI have tried all the possible directory combinations but it is kinda hard when you don't know what you are doing.
-
Again - when you want to compile something you need sources (at least it's the case for me, don't know if someone else can compile code without sources though). So you want to compile the Qt mysql driver you need theses sources. They're provided by your Qt online installer.
-
wrote on 23 Jun 2022, 17:35 last edited by
That would be a great starting point! But where and what should I be looking for? I have installed Qt via $ pip install PyQt6
-
That would be a great starting point! But where and what should I be looking for? I have installed Qt via $ pip install PyQt6
wrote on 23 Jun 2022, 17:39 last edited by@DanilZ
And I believe that is the problem/not sufficient.If you have to build drivers you are going to have to do C++ compilation on source code. I imagine PyQt installation does not provide the sources. You need to get the sources from a Qt installation download.
-
Lifetime Qt Championwrote on 23 Jun 2022, 17:40 last edited by Christian Ehrlicher
Or use another database like postgresql and blame mysql licensing. :)
-
wrote on 23 Jun 2022, 18:15 last edited by
-
Postgres looks like a good choice since among my available drivers I have QPSQL. But when changing the .addDatabase('QPSQL') I again get the same error:
I hope this one would be easier to mitigate?
wrote on 23 Jun 2022, 18:19 last edited by@DanilZ
While you await @Christian-EhrlicherEnter
export QT_DEBUG_PLUGINS=1
as a command and then re-run your command. Look through the diagnostic output for a clue as to why
QPSQL
is available but did not get loaded. -
wrote on 23 Jun 2022, 19:36 last edited by
-
Hi,
Did you install the Postgres application ?
-
wrote on 23 Jun 2022, 20:07 last edited by
That was the problem. Just installed it and now my program is failing at another point. But at least I've got passed the problem of initialising a DB object. Now it seems to be connecting to a database, thanks to you guys!
1/12