QMYSQL Driver Setup
-
Hello and sorry for my english,
I've been trying to install QMYSQL driver for 2 days without success. I use Windows.
I followed this doc : https://doc.qt.io/qt-5/sql-driver.htmlFrom "C:\Qt\5.14.1\Src", when I run this command :
configure -sql-mysql
or :
configure -sql-mysql MYSQL_PREFIX="C:\MySQL\MySQL Connector C 6.1" MYSQL_INCDIR="C:\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="C:\MySQL\MySQL Connector C 6.1\lib"
I have the following message :
ERROR: Feature 'sql-mysql' was enabled, but the pre-condition 'libs.mysql' failed.
In the config.log I have in particular :
test config.qtbase_sqldrivers.libraries.ibase FAILED loaded result for library config.qtbase_sqldrivers.libraries.mysql Trying source 0 (type mysqlConfig) of library mysql ... mysql_config not found. => source produced no result. Trying source 1 (type mysqlConfig) of library mysql ... mysql_config not found. => source produced no result. Trying source 2 (type mysqlConfig) of library mysql ... mysql_config not found. => source produced no result. Trying source 3 (type mysqlConfig) of library mysql ... mysql_config not found. => source produced no result. Trying source 4 (type inline) of library mysql ... => source failed condition '!config.win32'. Trying source 5 (type inline) of library mysql ... mysql.h not found in [] and global paths. => source produced no result. Trying source 6 (type inline) of library mysql ... => source failed condition '!config.win32'. test config.qtbase_sqldrivers.libraries.mysql FAILED
So the QMYSQL driver is not available in the driver list. I've only this :
['QSQLITE', 'QODBC', 'QODBC3', 'QPSQL', 'QPSQL7']
I verified that I have these 3 files :
"C:/MySQL/MySQL Connector C 6.1/lib/libmysql.lib" "C:/MySQL/MySQL Connector C 6.1/lib/libmysql.dll" "C:/MySQL/MySQL Connector C 6.1/include/mysql.h"
I tried many things as reinstall MySQL and Qt but it's always the same. I searched for hours on other similar topics but I never found the solution.
I need some help please :) -
Please follow the instructions at https://doc.qt.io/qt-5/sql-driver.html and report back when you encounter problems.
-
Hello,
The original problem is that with PyQt5, when I try to connect to a MYSQL database with :
db = QSqlDatabase.addDatabase("QMYSQL") db.setHostName("localhost") db.setUserName("root") db.setPassword("") db.setDatabaseName("test")
It fails to connect and when I run :
print(db.drivers())
The result is :
['QSQLITE', 'QODBC', 'QODBC3', 'QPSQL', 'QPSQL7']
So I'm investigating about why QMYSQL isn't in this list of available drivers and I tried the instructions in the link you provide (and that I provided in my first post too)
My problem is described in the firt post. I cannot activate the QMYSQL driver when I run the "configure -sql-mysql" command and the message is "the precondition 'libs.mysql' failed".
It is possible that I make something wrong as I am a beginner but I don't understand what and it's time to ask for help.
I this order, I did this :
Install Qt 5.14.1 with source Install MySQL Server Community 8.0 Install MySQL Connector C 6.1 Go to C:\Qt\5.14.1\Src>configure -sql-mysql
as described here: https://doc.qt.io/qt-5/sql-driver.html#building-the-drivers
EDIT: It's now OK with a Qt Project with this main.cpp
#include "mainwindow.h" #include <QApplication> #include <QtSql> using namespace std; int main(int argc, char *argv[]) { QApplication a(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("localhost"); db.setUserName("root"); db.setPassword(""); db.setDatabaseName("test"); if(db.open()) { qDebug()<< "connecté:" << db.open() << db.drivers(); db.close(); } else { qDebug()<< "non connecté:" << db.open(); } MainWindow w; w.show(); return a.exec(); }
The output is :
connecté: true ("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
The problem seems to be more with PyQt5 in fact...
-
Ok, I solved my problem with PyQt5 by copying "qsqlmysql.dll" from :
C:\Qt\5.14.1\mingw73_64\plugins\sqldrivers
To :
..\Python38\Lib\site-packages\PyQt5\Qt\plugins\sqldrivers
QMYSQL driver is now available :
['QSQLITE', 'QMYSQL', 'QMYSQL3', 'QODBC', 'QODBC3', 'QPSQL', 'QPSQL7']
I've not seen anywhere this instruction...
I have now the 'Driver not loaded' error but it's ok I've seen many subjects about it, I will search by myself.
Thank you.
-
Hi and welcome to devnet,
That's because there was a change in the licensing of MySQL. The driver can't be offered anymore under all Qt licences using their libraries.
-
Hi,
Thank you for this information, because I was still searching.
With PyQt, my goal is to link a tableview to a MySQL Database. (I already made the connexion with a tablewidget (thanks to pymysql) but i'd like to test Tableview for my project)
What do you recommend as an alternative to use Tableview and MySQL database ?
(I'm a beginner, don't hesitate to tell me if there are confusions in what I said)
-
The thing is: you need to build the MySQL module for the Qt version used by PySide2.
But since copying since to have at least given you access to it, first start by setting the QT_DEBUG_PLUGINS environment variable set to 1 and launch your python script. You'll have the plugins debug data printed and you'll see why it fails to load.