2

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?

Community
  • 1
  • 1
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
  • 1
    That's must most likely the problem, yes. Note that it reports libssl and libcrypto as missing, too. If your distro doesn't offer the mysqlclient in that version, you need to compile the mysql plugin yourself. – Frank Osterfeld May 22 '16 at 07:26

6 Answers6

5

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:

  1. install the development versions of the packages found above (libssl-dev, mysql-client-dev or similar).

  2. run the MaintenanceTool from your Qt installation, and be sure to select to install Qt's source code too.

  3. Go in QTDIR/5.6/Src/qtbase/src/plugins/sqldrivers/mysql/.

  4. 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.

  5. Run make. Hopefully this will just work™; if it complains about some missing libraries, install them and rerun make.

  6. This should now have produced a new libqsqlmysql.so plugin; overwrite the old one with this new one.

peppe
  • 21,934
  • 4
  • 55
  • 70
  • This did not "just work™" for me. What I had to do was steps 1 through 4, then edit Makefile and replace all occurances of "-std=c++1z" to "-std=c++11". The reason is that this was built on RHEL and I am on Ubuntu and the respective gcc suopport different -std= flags. – Mr. Developerdude Jan 31 '17 at 02:16
  • May I ask, what Qt version was that? In theory qmake should've picked the same flags used when compiling Qt itself. (Smelling like a bug) – peppe Feb 02 '17 at 16:16
  • Its latest & greatest 5.8 :) – Mr. Developerdude Feb 02 '17 at 17:07
  • Oh, Ubuntu version is 16.04 amd64 with gcc 4.9.3 – Mr. Developerdude Feb 02 '17 at 17:08
  • Aaaand, finally a comment . Why build on RHEL when 90% of end users are on Ubuntu? – Mr. Developerdude Feb 02 '17 at 17:10
  • But doesn't Ubuntu 16.04 ship with GCC 5.4.0? The "build on an old RHEL" story is to try to get maximum compatibility across the various Linux distributions. Otherwise you'd get a Qt which is not installable on anything but the latest releases (and, yes, there are still people running ancient stuff...). Where did you get the 90% number from? – peppe Feb 02 '17 at 19:03
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
Afriza N. Arief
  • 7,696
  • 5
  • 47
  • 74
1

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");
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
IVI
  • 1,893
  • 1
  • 16
  • 19
1

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

Haris
  • 13,645
  • 12
  • 90
  • 121
0

For use MySql with PyQt5 on Raspberry Pi, it's fine to install:

sudo apt-get install libqt5sql5-mysql

and

sudo apt-get install libqt5sql5-mysql
Obsidian
  • 3,719
  • 8
  • 17
  • 30
Alain
  • 1
0

To solve MYSQL driver not loaded and if you don't have MYSQL driver available with your Qt install:

First and foremost:

try install libqt5sql5-mysql, this is the easiest way.

$ sudo apt-get install libqt5sql5-mysql

If the issue still persists, then maybe you have installed Qt from source and didn't config it with MySQL driver. You have to build and install the driver yourself. Here is how to do it:

These following commands run in my VM: ubuntu20.04 with Qt5.14.0 installed

1. install dependency

$ sudo apt install libmysqlclient-dev

2. locate your Qt path.

It looks like Qt[version]/[version]/ and inside it will have a folder Src and gcc_64. Save this path to shell variable qtpath, for example, mine is:

$ qtpath=/opt/Qt5.14.0/5.14.0

3. Make && make install mysql driver (use sudo if neccessary):
$ cd $qtpath/Src/qtbase/src/plugins/sqldrivers 
$ sudo $qtpath/gcc_64/bin/qmake sqldrivers.pro 
$ sudo make 
$ sudo make install

After this, you will have a Sql driver built and installed with your version of Qt. However, if you have "ERROR: You cannot configure sqldrivers separately within a top-level build.” this means you have already run the configure script before. To resolve this, run:

$ cd $qtpath/Src
$ sudo ./configure -sql-mysql MYSQL_INCDIR=/usr/include/mysql MYSQL_LIBDIR=/usr/lib/x86_64-linux-gnu MYSQL_PREFIX=/usr/lib/x86_64-linux-gnu

If it success, you will have MySQL......Yes in the config note. Then run step 3 above again to build and install only the MySQL driver.