MYSQL driver not loaded when using mariadb on Debian Linux
-
I am using Debian 10 (which by default comes with mariadb instead of mysql. I have the mariadb 10.3 client and 10.3 server installed and functioning. I installed QT 5.11.3 using the apt install command. My version of QT Creator is 4.8.2.
The relevant code that I am using is:```
void MainWindow::on_pushButton_clicked()
{
QSqlDatabase db = QSqlDatabase::addDatabase("MYSQL");
db.setHostName("127.0.0.1");
db.setUserName("root");
db.setPassword("");
db.setDatabaseName("nation");if (db.open()) { QMessageBox::information(this, "Connection", "Database Connected Successfully"); } else{ QMessageBox::information(this, "Not Connected", "Database Is Not Connected"); }
}
The error that I get is :``` QSqlDatabase: MYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3
Any assistance in this matter would be appreciated.
-
libmysqlclient.so is in /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers, but it did not come the standard debian installation. I think it came from a ubuntu .deb file. Here is an extract of the output when application with QT_DEBUG_PLUGINS=1:
code_QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers" ... QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so" "Failed to extract plugin meta data from '/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so'" not a plugin QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so" Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QSQLITE" ] }, "className": "QSQLiteDriverPlugin", "debug": false, "version": 330499 } Got keys from plugin meta data ("QSQLITE") QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so" Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QMYSQL3", "QMYSQL" ] }, "className": "QMYSQLDriverPlugin", "debug": false, "version": 330499 } Got keys from plugin meta data ("QMYSQL3", "QMYSQL") QFactoryLoader::QFactoryLoader() checking directory path "/home/daniel/qtProjects/build-qt5database-Desktop-Debug/sqldrivers" ...text
The most important piece of the output is:
"Failed to extract plugin meta data from '/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so'" not a plugin
Is it possible to find a valid version of libmysqlclient.so?
-
libmysqlclient.so is in /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers, but it did not come the standard debian installation. I think it came from a ubuntu .deb file. Here is an extract of the output when application with QT_DEBUG_PLUGINS=1:
code_QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers" ... QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so" "Failed to extract plugin meta data from '/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so'" not a plugin QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so" Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QSQLITE" ] }, "className": "QSQLiteDriverPlugin", "debug": false, "version": 330499 } Got keys from plugin meta data ("QSQLITE") QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so" Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QMYSQL3", "QMYSQL" ] }, "className": "QMYSQLDriverPlugin", "debug": false, "version": 330499 } Got keys from plugin meta data ("QMYSQL3", "QMYSQL") QFactoryLoader::QFactoryLoader() checking directory path "/home/daniel/qtProjects/build-qt5database-Desktop-Debug/sqldrivers" ...text
The most important piece of the output is:
"Failed to extract plugin meta data from '/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so'" not a plugin
Is it possible to find a valid version of libmysqlclient.so?
@tataDanAz said in MYSQL driver not loaded when using mariadb on Debian Linux:
This is NOT Qt plug-in for MySql! This is the client library from MySql/MariaDB. Why is this file in /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers?!
The correct file name of the plug-in should be libqsqlmysq.soPlease search for MySQL in this forum: this is asked many many times and was answered many times.
-
libmysqlclient.so is in /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers, but it did not come the standard debian installation. I think it came from a ubuntu .deb file. Here is an extract of the output when application with QT_DEBUG_PLUGINS=1:
code_QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers" ... QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so" "Failed to extract plugin meta data from '/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so'" not a plugin QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so" Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QSQLITE" ] }, "className": "QSQLiteDriverPlugin", "debug": false, "version": 330499 } Got keys from plugin meta data ("QSQLITE") QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so" Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QMYSQL3", "QMYSQL" ] }, "className": "QMYSQLDriverPlugin", "debug": false, "version": 330499 } Got keys from plugin meta data ("QMYSQL3", "QMYSQL") QFactoryLoader::QFactoryLoader() checking directory path "/home/daniel/qtProjects/build-qt5database-Desktop-Debug/sqldrivers" ...text
The most important piece of the output is:
"Failed to extract plugin meta data from '/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so'" not a plugin
Is it possible to find a valid version of libmysqlclient.so?
@tataDanAz
No, it is not the most important piece, just because libmysqlclient.so is not supposed to be put in the plugin folder.
I think you should move it to the qt bin folder.
The most important piece should be about libqsqlmysql.so.
Is it loaded successfully? If not, what's the information? -
@Bonnie said in MYSQL driver not loaded when using mariadb on Debian Linux:
QT_DEBUG_PLUGINS
Apparently in Debian libmysqlclient.so is a symbolic link to libmariadbclient.so (at least that's what my limited understanding leads me to believe).
I copied both files from /usr/lib/x86_64-linux-gnu to /usr/lib/x86_64-linux-gnu/qt5/bin, but I still get the error. (I also tried copying them to /usr/lib/qt5/bin and the directory when my application resides, but that did not work either).
As far as I can tell, libqsqlmysql.so loaded successfully. Here is the latest extract from the output:QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so" Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QMYSQL3", "QMYSQL" ] }, "className": "QMYSQLDriverPlugin", "debug": false, "version": 330499 } Got keys from plugin meta data ("QMYSQL3", "QMYSQL") QFactoryLoader::QFactoryLoader() checking directory path "/home/daniel/qtProjects/build-qt5database-Desktop-Debug/sqldrivers" ... QSqlDatabase: MYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3
-
I finally discovered the problem. It was a problem in my code.
Instead of writingQSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
I wrote
QSqlDatabase db = QSqlDatabase::addDatabase("MYSQL");
I was attempting to enter the code from a youtube video and I left out a "Q".
Thanks to all who attempted to help me. I hope that I didn't cause anybody too much difficulty in trying to help me.