Solved MySQL drivers on Ubuntu 20.04
-
I've been struggling with getting Qt to cooperate with my MySQL driver for a little while. Here's some context:
- Ubuntu 20.04.2 LTS
- Qt has been installed through the online installer without any issues to
~/Qt
Qt Source 5.15.2
Qt Creator 4.15.0
OpenSSL 1.1.1j Toolkit
installed through installer- MySQL package is installed through
sudo apt install libmysqlclient-dev
- MySQL driver (
libqsqlmysql.so
) has been built and installed successfully through following the documentation and installed usingmake install
I'm running a very simple project with the following code in mainwindow.cpp
QSqlDatabase db = QSqlDatabase(); db.addDatabase("QMYSQL"); db.setUserName("JDog"); db.setPassword("*********"); db.setHostName("192.168.2.22"); db.setDatabaseName("test"); if (!db.open()) { qDebug() << db.lastError().text(); }
The error I'm getting is really odd, it recognises the driver for MySQL is there, but simply displays the error
Driver not loaded Driver not loaded
when I try to open the db. When enabling
QT_DEBUG_PLUGINS=1
, I get the following relevant output:QFactoryLoader::QFactoryLoader() looking at "/home/jgrant/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlmysql.so" Found metadata in lib /home/jgrant/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlmysql.so, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QMYSQL3", "QMYSQL", "QMARIADB" ] }, "archreq": 0, "className": "QMYSQLDriverPlugin", "debug": false, "version": 331520 } Got keys from plugin meta data ("QMYSQL3", "QMYSQL", "QMARIADB") QFactoryLoader::QFactoryLoader() looking at "/home/jgrant/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlmysql.so.debug" "The shared library was not found." not a plugin
I thought the line
"The shared library was not found."
might have been a clue, so I also made sure all the dependencies could be found forlibqsqlmysql.so
by runningldd /home/jgrant/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlmysql.so
. All dependencies were found.Does anyone have any ideas what I should pursue? Any thoughts would be greatly appreciated.
Thanks
-
Welp... it's this line in the sample code:
db.addDatabase("QMYSQL");
I was calling a static function and not doing anything with the return value. Should be this:
db = QSqlDatabase::addDatabase("QMYSQL");
-
@JohnDog
You say you looked at dependencies oflibqsqlmysql.so
but the message said it was looking atlibqsqlmysql.so.debug
? -
Hi,
From the looks of it, you only built the release version of the plugin. Is that correct ?
-
@JonB Thanks for the reply.
I tried to do ldd on the debug version but it returns
not a dynamic executable
@SGaist Thanks for the reply too.
I followed the documentation, and don't see anything about building the debug vs release versions.
make install
returned:cd mysql/ && ( test -e Makefile || /home/jgrant/Qt/5.15.2/gcc_64/bin/qmake -o Makefile /home/jgrant/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/mysql/mysql.pro ) && make -f Makefile install make[1]: Entering directory '/home/jgrant/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/mysql' /home/jgrant/Qt/5.15.2/gcc_64/bin/qmake -install qinstall /home/jgrant/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/plugins/sqldrivers/libqsqlmysql.so.debug /home/jgrant/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlmysql.so.debug /home/jgrant/Qt/5.15.2/gcc_64/bin/qmake -install qinstall -exe ../plugins/sqldrivers/libqsqlmysql.so /home/jgrant/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlmysql.so /home/jgrant/Qt/5.15.2/gcc_64/bin/qmake -install qinstall /home/jgrant/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/lib/cmake/Qt5Sql/Qt5Sql_QMYSQLDriverPlugin.cmake /home/jgrant/Qt/5.15.2/gcc_64/lib/cmake/Qt5Sql/Qt5Sql_QMYSQLDriverPlugin.cmake make[1]: Leaving directory '/home/jgrant/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/mysql'
Doesn't that show it installing the debug version too?
-
@JohnDog said in MySQL drivers on Ubuntu 20.04:
I tried to do ldd on the debug version but it returns not a dynamic executable
Exactly. And I think that's the cause of your problem & error message. It is looking at that
libqsqlmysql.so.debug
file, which is not acceptable. I don't know why. Doubtless @SGaist will clarify :) -
What do you get if you call
file
on your debug plugin ? -
@SGaist it returns:
file /home/jgrant/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlmysql.so.debug /home/jgrant/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlmysql.so.debug: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=59b14f1c0abdd042fba77a048bfce8b319a44243, with debug_info, not stripped
-
That part looks good...
What about the permission with regard to the release plugin ?
-
@SGaist Hope you had a good weekend, thanks for the ongoing help.
Originally there weren't any execute permissions on the debug versions:
ls -l total 13084 -rwxr-xr-x 1 jgrant jgrant 1356696 May 27 15:32 libqsqlite.so -rw-r--r-- 1 jgrant jgrant 7675792 May 27 15:32 libqsqlite.so.debug -rwxr-xr-x 1 jgrant jgrant 112416 May 27 15:32 libqsqlmysql.so -rw-r--r-- 1 jgrant jgrant 1499400 May 27 15:32 libqsqlmysql.so.debug -rwxr-xr-x 1 jgrant jgrant 119360 Nov 6 2020 libqsqlodbc.so -rw-r--r-- 1 jgrant jgrant 1204520 Nov 6 2020 libqsqlodbc.so.debug -rwxr-xr-x 1 jgrant jgrant 115032 Nov 6 2020 libqsqlpsql.so -rw-r--r-- 1 jgrant jgrant 1292544 Nov 6 2020 libqsqlpsql.so.debug
so I modified all the plugins to have it:
chmod -R 755 ./ ls -l total 13084 -rwxr-xr-x 1 jgrant jgrant 1356696 May 27 15:32 libqsqlite.so -rwxr-xr-x 1 jgrant jgrant 7675792 May 27 15:32 libqsqlite.so.debug -rwxr-xr-x 1 jgrant jgrant 112416 May 27 15:32 libqsqlmysql.so -rwxr-xr-x 1 jgrant jgrant 1499400 May 27 15:32 libqsqlmysql.so.debug -rwxr-xr-x 1 jgrant jgrant 119360 Nov 6 2020 libqsqlodbc.so -rwxr-xr-x 1 jgrant jgrant 1204520 Nov 6 2020 libqsqlodbc.so.debug -rwxr-xr-x 1 jgrant jgrant 115032 Nov 6 2020 libqsqlpsql.so -rwxr-xr-x 1 jgrant jgrant 1292544 Nov 6 2020 libqsqlpsql.so.debug
Unfortunately I'm still getting the
Driver not loaded Driver not loaded
error when trying to open the DB. -
Did you get something different in the output generate by QT_DEBUG_PLUGINS ?
-
No, unfortunately everything looks normal. This is a fresh install of Ubuntu and everything too, not much else could be interfering.
-
Welp... it's this line in the sample code:
db.addDatabase("QMYSQL");
I was calling a static function and not doing anything with the return value. Should be this:
db = QSqlDatabase::addDatabase("QMYSQL");
-
My eyes are getting old...
The bulk of the questions regarding MySQL is usually unrelated to the wrong use of addDatabase that it passed by.
-
@SGaist no worries, thanks for your patience and help! I should have caught it earlier too