QSqlDatabase: QMYSQL driver not loaded on Ubuntu 15.04 64bits
Solution 1:
First and foremost, double check that you have the packages containing libssl.so
, libcrypto.so
and libmysqlclient_r.so
installed (looks like you have this last one, it's extremely likely you also have the first two, but just double check).
Then, your problem is that you have those shared objects with a different SONAME, sign that they're binary incompatible with the plugin shipped with Qt, which therefore needs to be recompiled.
Therefore:
install the development versions of the packages found above (
libssl-dev
,mysql-client-dev
or similar).run the
MaintenanceTool
from your Qt installation, and be sure to select to install Qt's source code too.Go in
QTDIR/5.6/Src/qtbase/src/plugins/sqldrivers/mysql/
.Run the right
qmake
, i.e. the one coming from that installation of Qt (not the system wide one or similar). Best way to be sure is providing the full path to it:QTDIR/5.6/gcc_64/bin/qmake
.Run
make
. Hopefully this will just work™; if it complains about some missing libraries, install them and rerunmake
.This should now have produced a new
libqsqlmysql.so
plugin; overwrite the old one with this new one.
Solution 2:
I am using Ubuntu 18.04.4 and compiling my project using system's Qt5. The driver is successfully loaded after I install libqt5sql5-mysql
package.
sudo apt-get install libqt5sql5-mysql
Solution 3:
There are two fixes for this issue. First try and locate the qtbase folder located within your qt directory and try run ./configure -plugin-sql-mysql which will activate the driver if they're missing.
If this doesn't solve your issue, I suggest that you double check your code and try running one of the Qt examples which makes a connection to the Sql databases. I.e. modify the example code which connects to a local SQLite database changing the parameter to MySQL. If this example doesn't throw 'Driver not loaded error' then follow the step below.
Make sure you're using the static function of the QSqlDatabase i.e. rather than using
QSqlDatabase *db = new QSqlDatabase();
db->addDatabase("QMYSQL");
you should be doing
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");