Congratulations to our 2022 Qt Champions!

QMYSQL driver not loaded, but source file not found to rebuild

  • Hi,

    I have the age old issue, but surprisingly I haven't found much solution (I am new to GNU/Linux development and Qt). So when I run a program to use MySQL,

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

    it throws the age-old, much-referred error message:

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

    I found the below files at the Qt plugins directory.

    When I did ldd, the below is the line that's of issue: => not found

    I have libqt5sql5-mysql and it's version 20.


    • I tried tricking the program by creating symbolic link as but it does't work

    • list itemCopy the file from the /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/ to the Qt plugins folder and run (got the error: Cannot mix incompatible Qt library (version 0x50601) with this library (version 0x50700))
      Ran maint

    • list itemenance tool, added the repository manually, but found no source packages

    • list itemled Qt and this time selected the source package and installed, but no source for mysqldrivers found to compile

    I am stuck for 2 weeks with no help. I will have to either fix this issue dump Qt and look into Gtk or Mono.

    Ubuntu: 16.10
    Qt Versions: Qt Creator 4.0.2, Qt: 5.7.0

    Please help.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    2 solutions:

    1. Use your distribution provided Qt
    2. Build the plugin yourself.

    For 2:

    1. Download the Qt sources through e.g. the Maintenance tool
    2. Install the MySQL dev package for your distribution
    3. Follow the documentation on how to build the plugin
    4. Don't forget to call make install once built.

  • Lifetime Qt Champion

    By the way, the plugin sources are in qtbase.

  • @SGaist thanks, worked, but found another error saying that the Qt5 Kit is not a valid one. After a bit of searching, I had to install "qt5-default" to resolve this.

    Thanks a lot.

  • Lifetime Qt Champion

    How did you setup Qt ?

    Looks like you are mixing the one from your distribution and the one from the official installer.

  • I have the same problem. i got the error MYSQdriver not loaded and i have followed all suggestions in forums but the issue is not fixed. can someone help me please?



  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What exactly don't work ?
    What error are you getting ?
    Did you follow the step by step guide I wrote earlier ?
    If so, did one of the point fail at any time ?
    What version of Qt are you using ?
    On what OS ?
    With what compiler ?

  • im using linux mint 18. Qt version 5.1.1. i received this error: mysql driver not loaded. yes i have try all these suggestions but i don't know how to begin since im new in linux

  • ldd /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/ => (0x00007ffedfdda000) => /usr/lib/x86_64-linux-gnu/ (0x00007f949e3a8000) => /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/../../lib/ (0x00007f949e169000) => /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/../../lib/ (0x00007f949dade000) => /usr/lib/x86_64-linux-gnu/ (0x00007f949d75c000) => /lib/x86_64-linux-gnu/ (0x00007f949d393000) => /lib/x86_64-linux-gnu/ (0x00007f949d175000) => /lib/x86_64-linux-gnu/ (0x00007f949ce6c000) => /lib/x86_64-linux-gnu/ (0x00007f949cc52000) => /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/../../lib/ (0x00007f949c838000) => /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/../../lib/ (0x00007f949c4b2000) => /lib/x86_64-linux-gnu/ (0x00007f949c2ae000) => /usr/lib/x86_64-linux-gnu/ (0x00007f949c0ab000) => /lib/x86_64-linux-gnu/ (0x00007f949bea3000) => /lib/x86_64-linux-gnu/ (0x00007f949bb92000) => /lib/x86_64-linux-gnu/ (0x00007f949b97b000)
    /lib64/ (0x000055c820f7a000) => /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/../../lib/ (0x00007f949a232000) => /lib/x86_64-linux-gnu/ (0x00007f9499fc1000)

  • Lifetime Qt Champion

    Did you also print the exact error you got ?

    The plugin looks fine.

  • 0_1481840852645_upload-a114047b-129c-4c7a-b22d-5f25d662ab65

    #include <QCoreApplication>

    #include <QtSql/QSql>
    #include <QtSql/QSqlDatabase>
    #include <QtSql/QSqlDriver>
    #include <QtSql/QSqlQuery>
    #include <QDebug>

    bool createConnection();

    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);
    if (!createConnection()){
    qDebug() << "Not connected!";
    return 1;
    qDebug() << "Connected";
    QSqlQuery query;
    query.exec("SELECT name FROM student");

        while ( {
            QString name = query.value(0).toString();
            qDebug() << "name:" << name;
        return 0;
    return a.exec();


    bool createConnection() {

    // QApplication::addLibraryPath("/home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers");
    QSqlDatabase db = QSqlDatabase::addDatabase("QSLITE");
    // db.setPort(3306);
    // QSqlDriver *driver = QSqlDatabase::database().driver();
    qDebug() << "Database error occurred";
    return false;

    return true;



    Project created by QtCreator 2016-12-15T19:04:16


    QT += core sql

    QT -= gui

    TARGET = test
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

  • the plugin looks fine but im still getting a error. i don'tknow exactly what wrong

  • Lifetime Qt Champion

    You are not use the MySQL driver and you are using the wrong name for the SQLite driver. It's QSQLITE.

  • i tried mysql, sqlite, postgres i m having the same error

  • Lifetime Qt Champion

    Print the text returned by db.lastError()

    Just saying that it doesn't work with the "Driver not loaded" message doesn't help much.

    Based on your current code, it's not really surprising:

    1. You gave the driver name wrong.
    2. You are mixing the setup for the sqlite driver with the setup for a server based database.

    One other important detail: do you have any of the SQL server running on your machine to connect to ? Is it properly configured ?

  • Thank you dear friend .

    You're right . the drivers names were wrong . it works now

Log in to reply