In Ubuntu 15.04 64 bits I installed Qt5.6 (online installer) and while trying to move my development environment from Windows 7 to Linux I faced the following:
SqlDatabase: QMYSQL driver not loaded
Following this, I managed to find ~/Qt/5.6/gcc_64/plugins/sqldrivers/libqsqlmysql.so
and then:
$ ldd libqsqlmysql.so
linux-vdso.so.1 => (0x00007ffffd571000)
libmysqlclient_r.so.16 => not found
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe94ef24000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007fe94ecec000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fe94ead2000)
libssl.so.10 => not found
libcrypto.so.10 => not found
libQt5Sql.so.5 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libQt5Sql.so.5 (0x00007fe94e88d000)
libQt5Core.so.5 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libQt5Core.so.5 (0x00007fe94e17a000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe94df5c000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe94dc4d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe94d944000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe94d72e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe94d364000)
libicui18n.so.56 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libicui18n.so.56 (0x00007fe94cec9000)
libicuuc.so.56 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libicuuc.so.56 (0x00007fe94cb11000)
libicudata.so.56 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libicudata.so.56 (0x00007fe94b12e000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe94af29000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fe94ad27000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe94ab1f000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fe94a80f000)
/lib64/ld-linux-x86-64.so.2 (0x000056024837f000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fe94a5a2000)
Tells libmysqlclient_r.so.16 => not found
. In fact, it seems I have a newer version:
find / -name libmysqlclient_r*
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.18
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.18.1.0
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.a
Perhaps that's the problem. Could some one confirm? How should I proceed?
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.
I also have the same problem with Qt5.11.1
and my OS is Ubuntu16.04
and I have resolve the problem by installing libmysqlclient18
from here
https://launchpad.net/ubuntu/xenial/amd64/libmysqlclient18/5.6.25-0ubuntu1
After download run the command from download directory,
sudo dpkg -i libmysqlclient18_5.6.25-0ubuntu1_amd64.deb
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");
来源:https://stackoverflow.com/questions/37369480/qsqldatabase-qmysql-driver-not-loaded-on-ubuntu-15-04-64bits