Congratulations to our 2022 Qt Champions!

[Solved] New Qt install and MySql

  • Hi all,

    I need some help getting MySQL running with my Qt server application. There are lots of other posts/search results for this, but I have what may be basic questions that never seem to be answered.

    My setup:

    Linux Mint
    Qt 5.4 (open source/community) installed from website to /home/matt/Qt
    MySql Server 5.5 installed from repo

    I'm trying to build a client/server application. While developing, the client, server and mysql server will all run on the same machine. When deployed all 3 can and will be running on different machines (client on Windows, server and mysql server on Linux).

    According to "this page": Qt comes packaged with a driver for mysql and there is a file called in this location:


    But the page also says 'not all of the plugins are provided with Open Source Versions of Qt'. So which drivers aren't? I've tried to connect to my mysql database but get the following error:

    @QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7@

    using this code:

    @ QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");

    Do I need to build the driver for mysql for my setup?
    What are the actual requirements for getting this to work with my development setup (i.e. 1 machine) and later on with the server app and database server running on different machines?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Do you have the MySQL client libraries installed on your machine ?

  • Hi SGAist, thanks for your reply. I'm not sure if the client libraries are installed - what are they?

    I have mysql-client and mysql-server installed, and apt-get offers these other options for mysql*:


    Thanks again,

  • Lifetime Qt Champion

    Ok, then run ldd on the plugin to check if everything it needs can be found

  • Do you mean this file:


    If so, this is the ldd output: => (0x00007fff6bda5000) => not found => /home/matt/Qt/5.4/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007fd0a85db000) => /home/matt/Qt/5.4/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007fd0a7e9e000) => /usr/lib/x86_64-linux-gnu/ (0x00007fd0a7b9a000) => /lib/x86_64-linux-gnu/ (0x00007fd0a77d2000) => /lib/x86_64-linux-gnu/ (0x00007fd0a75b4000) => /home/matt/Qt/5.4/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007fd0a7168000) => /home/matt/Qt/5.4/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007fd0a6ddd000) => /lib/x86_64-linux-gnu/ (0x00007fd0a6bd8000) => /usr/lib/x86_64-linux-gnu/ (0x00007fd0a69d6000) => /lib/x86_64-linux-gnu/ (0x00007fd0a67ce000) => /lib/x86_64-linux-gnu/ (0x00007fd0a64cc000) => /lib/x86_64-linux-gnu/ (0x00007fd0a61c8000) => /lib/x86_64-linux-gnu/ (0x00007fd0a5fb2000)
    /lib64/ (0x00007fd0a8a4a000) => /home/matt/Qt/5.4/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007fd0a4929000) => /lib/x86_64-linux-gnu/ (0x00007fd0a46ea000)@

    I'm guessing this is the problem? => not found@

    But I have no idea why, or how to fix it!

  • Lifetime Qt Champion

    You probably have on your system so you can either try to get version 16 installed or rebuild the plugin to use your currently installed library version

  • OK, thanks. In this context are 'plugin' and 'driver' the same thing? In both cases is it this file:

    /home/matt/Qt/5.4/gcc_64/plugins/sqldrivers/ ?

    And this file plugin/driver (that came with my install of Qt) has been built with version 16?

    I will try to build it using the instructions "here":

  • Thanks SGaist, that got it working - it turned out I had version 18.

    One thing I didn't find too clear in the instructions was what the 'INCLUDEPATH' should be so left it as:


    It seemed to work even though there is nothing in that folder on my system.

    How does Qt/my application know where to look for the driver? When I move the server application to a new system where should the driver go?

  • Lifetime Qt Champion

    That's because you have a distribution installed MySQL which put dev package content in common places.

    It's built in the library, if you take a look at the folder structure of Qt you'll see how it works..

    How do you plan to distribute your application ??

Log in to reply