Search code examples
mysqlqtdriver

Qt5 MYSQL driver not loaded error


I have a Fedora 27 64bit OS, and am trying to run a Qt based app which is trying to access a MySQL server (which I can successfully reach from the command line). But my app shows these errors:

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
ERROR: DATABASE: Open failed with error code [-1].  Driver error [Driver not loaded].  Database error [Driver not loaded]

I've tried everything I could find online but can't solve this. When I check the libqsqlmysql.so dependencies I see:

[root@host lib64]# ldd /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/libqsqlmysql.so 
/home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/libqsqlmysql.so: /lib64/libmysqlclient_r.so.16: version `libmysqlclient_16' not found (required by /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/libqsqlmysql.so)
    linux-vdso.so.1 (0x00007fffde4ef000)
    libmysqlclient_r.so.16 => /lib64/libmysqlclient_r.so.16 (0x00007f3188fd8000)
    libz.so.1 => /lib64/libz.so.1 (0x00007f3188dc1000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f3188b8b000)
    libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f3188971000)
    libssl.so.10 => /lib64/libssl.so.10 (0x00007f3188705000)
    libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f31882a7000)
    libQt5Sql.so.5 => /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/../../lib/libQt5Sql.so.5 (0x00007f3188062000)
    libQt5Core.so.5 => /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/../../lib/libQt5Core.so.5 (0x00007f3187944000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f3187725000)
    libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f318739f000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f318704a000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f3186e33000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f3186a50000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f318684c000)
    libssl.so.1.1 => /lib64/libssl.so.1.1 (0x00007f31865e0000)
    libcrypto.so.1.1 => /lib64/libcrypto.so.1.1 (0x00007f3186158000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007f3185f55000)
    libicui18n.so.56 => /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/../../lib/libicui18n.so.56 (0x00007f3185abb000)
    libicuuc.so.56 => /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/../../lib/libicuuc.so.56 (0x00007f3185703000)
    libicudata.so.56 => /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/../../lib/libicudata.so.56 (0x00007f3183d20000)
    libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007f3183b1e000)
    librt.so.1 => /lib64/librt.so.1 (0x00007f3183916000)
    libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f3183602000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f3189440000)
    libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f318338f000)

and sure enough there is no /lib64/libmysqlclient_r.so.16 on my system. And DNF says that nothing provides this file! So I tried to symlink /lib64/libmysqlclient_r.so to /lib64/libmysqlclient_r.so.16 but still no joy.

Can someone offer a solution?


Solution

  • After lots of searching on different sites, the consensus was to recompile the Qt sql drivers from source (which is installed with Qt Creator). Switch to the source directory for SQL drivers then 'make', and 'make install'

    After that the error was gone.

    Ignore all the suggestions about copying/symlinking different .so files. It doesn't work (anymore).