Important: Please read the Qt Code of Conduct -

QMYSQL Driver not loaded but available

  • Hello, I am having problems building the QMYSQL plugin. I've read a number of forum posts and tried a bunch of solutions, but have not had any luck. Here is some background information:


    Qt 5.10.0
    Ubuntu 16.04
    MySQL 5.7.20

    Here is the code I'm using to connect to the database:

    db = QSqlDatabase::addDatabase("QMYSQL");
            bool ok =;

    Results of locate mysqlclient command


    Results of ldd in the qt plugins directory: =>  (0x00007ffca2ac6000) => /home/seth/Qt/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007ff6a5df1000) => /home/seth/Qt/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007ff6a56a3000) => /lib/x86_64-linux-gnu/ (0x00007ff6a5469000) => not found => /usr/lib/x86_64-linux-gnu/ (0x00007ff6a50e7000) => /lib/x86_64-linux-gnu/ (0x00007ff6a4ddd000) => /lib/x86_64-linux-gnu/ (0x00007ff6a4bc7000) => /lib/x86_64-linux-gnu/ (0x00007ff6a47fd000) => /lib/x86_64-linux-gnu/ (0x00007ff6a45e2000) => /home/seth/Qt/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007ff6a4149000) => /home/seth/Qt/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007ff6a3d91000) => /home/seth/Qt/5.10.0/gcc_64/plugins/sqldrivers/./../../lib/ (0x00007ff6a23ad000) => /lib/x86_64-linux-gnu/ (0x00007ff6a21a9000) => /usr/lib/x86_64-linux-gnu/ (0x00007ff6a1fa7000) => /lib/x86_64-linux-gnu/ (0x00007ff6a1c95000)
    /lib64/ (0x000055e8a1956000) => /lib/x86_64-linux-gnu/ (0x00007ff6a1a25000)

    Other things I've tried:

    Running qmake from the terminal as such:

    ~/Qt/5.10.0/Src/qtbase/src/plugins/sqldrivers/mysql$ qmake "INCLUDEPATH+=/usr/include" "LIBS+=-L/usr/lib/x86_64-linux-gnu/lib -lmysqlclient_r"


    Cannot read /home/seth/Qt/5.10.0/Src/qtbase/src/plugins/sqldrivers/qtsqldrivers-config.pri: No such file or directory

    I'm basically stumped at this point, and fairly frustrated. I feel like the documentation around building sql plugins is very lacking. Any ideas or different approaches to solving this problem are greatly appreciated!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    As you could see you have version 20 of the client library while the Qt plugin was built against 18.

    IIRC, with the latest changes that happened to the build system, you have to do a full configure run (no need to build all of Qt at all) and then you should be able to build the plugin by hand.

    I recommend doing that out of source so you can nuke everything if something goes wrong and try again.

  • Thanks for the fast response. Can you give further details on some of your instructions, as I'm very new to Qt programming and programming in general, so still learning how to configure dependencies.

    1. How do I do a "full configure run"? From the command line, within Qt? What commands do I need to run, and how do I make sure Qt is configured to work with version 20 of the client library?
    2. I'm not quite sure what you mean by "build the plugin by hand." I've seen the documentation here, but to be honest I've found it quite unclear as a novice user how to build a plugin from this documentation, and I have a sense there may be some pre-requisites which I'm missing. If you could give a step-by-step on how to build the plugin from hand, I wold really appreciate it!
    3. Last one! What do you mean by "out of source"? I've read the term "Qt source" thrown around quite a bit on forums, but have not been able to find a clear, consistent definition. Any clarity here would be great!


  • Lifetime Qt Champion

      1. Download Qt's sources,
      2. Install the MySQL dev package from your distribution package manager
      3. Call the configure script from the qtbase module (do it out of source)
    1. See number 1 and then you can go on and build directly the plugin

    2. Literally what the expression means: not in the same folder as your source code.

    mkdir build_qtbase
    pushd build_qtbase

    That's how you do an out of source build of Qt (minus the installation step)

  • @SGaist When you say Download Qt's sources, do you literally mean the source code? I.e -->

    Why does the download that I have not work? Also, I believe I have already installed the MySQL dev package. Not trying to be difficult here, would just like to understand!


  • I believe I am making progress. Found a good resource. Here's a more open-ended question: how would one know they needed to compile Qt from source code in order to use MySQL? It's definitely not spelled out anywhere in the documentation that I could find, and it's taken me the better part of a week (off and on) to troubleshoot it. Is this just a weird edge-case that doesn't happen often, or is the standard way that all development packages should be installed to ensure dependencies are met?

  • OK, I followed the instructions here and it looks like everything built correctly. However, when I now try to build the plugin in the terminal using:

    seth@seth-XPS-L521X:~/qt-everywhere-src-5.10.0/qtbase/plugins/sqldrivers$ qmake "INCLUDEPATH+=/usr/include" "LIBS+=-L/usr/lib/mysql -lmysqlclient_r"

    I get the message:

    Cannot find file:


  • Lifetime Qt Champion

    @SethTales Is there in ~/qt-everywhere-src-5.10.0/qtbase/plugins/sqldrivers ? I guess it is in mysql subdirectory?

  • No there is not. In fact, I can't find a file anywhere on my system. Is this a file I need to create?

  • Do I need to explicitly call qmake from the qt-everywhere-src-5.10.0 folder?

  • Lifetime Qt Champion

    It should be in qtbase/src/plugins/sqldrivers/mysql/. If not then you should consider re-downloading the sources.

  • It is not there. How do I ensure that it is there when I re-download the sources?

  • Lifetime Qt Champion

    1. Download the sources
    2. Un-compress the archive
    3. Take a look in the folder mentioned before

  • OK, but what if the file is not in the folder above? I ask because since I will be downloading the same archive as I used earlier, that has led me to the problem of the file not being there. I assume this will be the case again. If this is the case, how to I obtain sources that contain the proper files for making the plugin with mysql?

  • Lifetime Qt Champion

    Where did you get the sources from ?

  • I downloaded the tar.xz archive from

  • @SethTales said in QMYSQL Driver not loaded but available:

    Here's a more open-ended question: how would one know they needed to compile Qt from source code in order to use MySQL?

    Just to be clear: You do not have to compile Qt from source code to use MySQL (or almost anything else). You have to because you are choosing the latest Qt release, 5.10.

    Instead, you are using Ubuntu 16.04, you could accept the pre-compiled packages, available through standard apt-get, for the version of Qt that was current at the time 16.04 was released. I think that was Qt 5.5., BTW.

    For example, I use Ubuntu 17.04 now, and the apt-get package gives me Qt 5.7.1. Similarly, I use whatever the version of MySQL was for 17.04. I have not fetched a line of source code or done any compiling at all. And thankful for that!

    When 18.04 comes out, I will do same, upgrading to whatever versions of Qt & MySQL are available then through apt-get.

    So it in part depends on whether you need the latest version of Qt or not.

  • @JonB Thank you for the clarification! That makes a ton more sense. I was beginning to wonder why connecting to a database is seemingly giving so many people so much trouble!

    I've actually figured out a different way to solve the problem by using C++ MySQL Connector libraries provided by Oracle, and have gotten it working in my application! I will also try using the Qt and MySQL versions provided by my Ubuntu release and see how that goes.

Log in to reply