Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlDatabase: QMYSQL driver not loaded
Forum Updated to NodeBB v4.3 + New Features

QSqlDatabase: QMYSQL driver not loaded

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • joeQJ Offline
    joeQJ Offline
    joeQ
    wrote on last edited by
    #1

    I had installed mysql before days. about mysql like below information:

    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 31
    Server version: 5.7.19-0ubuntu0.16.04.1 (Ubuntu)
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | sakila             |
    +--------------------+
    2 rows in set (0.06 sec)
    

    I begin to use the Qt to connect mysql, like below snippet:

        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("localhost");
        db.setDatabaseName("sakila");
        db.setUserName("xxx");
        db.setPassword("xxxxxx");
        bool bOpenOk = db.open();
        if(!bOpenOk){
            qDebug() << db.lastError().text();
        }
    
        if(db.isOpen()){
            db.close();
        }
    

    Error

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

    I searched the error in internet. and find some way.

    1. use ldd
    :~/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers$ l
    libqsqlite.so*  libqsqlmysql.so*  libqsqlpsql.so*
    
    :~/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers$ ldd libqsqlmysql.so | grep "not found"
    ibmysqlclient.so.18 => not found
    
    :/usr/lib/x86_64-linux-gnu$ ls libmysqlclient*
    libmysqlclient.a
    libmysqlclient.so -> libmysqlclient.so.20
    libmysqlclient.so.20 -> libmysqlclient.so.20.3.6
    libmysqlclient.so.20.3.6
    
    :/usr/lib/x86_64-linux-gnu$ sudo cp libmysqlclient.so.20.3.6 libmysqlclient.so.18
    
    1. and use ldd again, had other error
    :~/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers$ ldd libqsqlmysql.so | grep "not found"
    ./libqsqlmysql.so: /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18: version `libmysqlclient_18' not found (required by ./libqsqlmysql.so)
    

    I also tried use ln -s, but, not work, had the same error.
    I also tried use apt install libmysqlcliend18-dev, but not found the package.
    I had tried many ways from internet, not work. like below links:

    forum.qt.io
    stack overflow

    I also had the libssl and libcryto error, and from below way, i worked it out.

    askubuntu.com

    How to work it out about QMYSQL driver not loaded ?

    Just do it!

    kshegunovK 1 Reply Last reply
    0
    • joeQJ joeQ

      I had installed mysql before days. about mysql like below information:

      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 31
      Server version: 5.7.19-0ubuntu0.16.04.1 (Ubuntu)
      
      mysql> show databases;
      +--------------------+
      | Database           |
      +--------------------+
      | information_schema |
      | sakila             |
      +--------------------+
      2 rows in set (0.06 sec)
      

      I begin to use the Qt to connect mysql, like below snippet:

          QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
          db.setHostName("localhost");
          db.setDatabaseName("sakila");
          db.setUserName("xxx");
          db.setPassword("xxxxxx");
          bool bOpenOk = db.open();
          if(!bOpenOk){
              qDebug() << db.lastError().text();
          }
      
          if(db.isOpen()){
              db.close();
          }
      

      Error

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

      I searched the error in internet. and find some way.

      1. use ldd
      :~/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers$ l
      libqsqlite.so*  libqsqlmysql.so*  libqsqlpsql.so*
      
      :~/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers$ ldd libqsqlmysql.so | grep "not found"
      ibmysqlclient.so.18 => not found
      
      :/usr/lib/x86_64-linux-gnu$ ls libmysqlclient*
      libmysqlclient.a
      libmysqlclient.so -> libmysqlclient.so.20
      libmysqlclient.so.20 -> libmysqlclient.so.20.3.6
      libmysqlclient.so.20.3.6
      
      :/usr/lib/x86_64-linux-gnu$ sudo cp libmysqlclient.so.20.3.6 libmysqlclient.so.18
      
      1. and use ldd again, had other error
      :~/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers$ ldd libqsqlmysql.so | grep "not found"
      ./libqsqlmysql.so: /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18: version `libmysqlclient_18' not found (required by ./libqsqlmysql.so)
      

      I also tried use ln -s, but, not work, had the same error.
      I also tried use apt install libmysqlcliend18-dev, but not found the package.
      I had tried many ways from internet, not work. like below links:

      forum.qt.io
      stack overflow

      I also had the libssl and libcryto error, and from below way, i worked it out.

      askubuntu.com

      How to work it out about QMYSQL driver not loaded ?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      You have a version mismatch from what I can tell. Your Qt's plugin is linked against one version of the mysqlclient library and you have another version in your system path.

      Read and abide by the Qt Code of Conduct

      joeQJ 2 Replies Last reply
      2
      • kshegunovK kshegunov

        You have a version mismatch from what I can tell. Your Qt's plugin is linked against one version of the mysqlclient library and you have another version in your system path.

        joeQJ Offline
        joeQJ Offline
        joeQ
        wrote on last edited by
        #3

        @kshegunov Thank you very much.

        and which version of Qt support libmysqlclient.so.20 ? or how to update libqsqlmysql.so let it to support libmysqlclient.so.20?

        or which version of MySql has libmysqlclient.so.18?

        if there is one way that just to update libqsqlmysql.so let it to support libmysqlclient.so.20, it is better way for me.

        Just do it!

        1 Reply Last reply
        0
        • kshegunovK kshegunov

          You have a version mismatch from what I can tell. Your Qt's plugin is linked against one version of the mysqlclient library and you have another version in your system path.

          joeQJ Offline
          joeQJ Offline
          joeQ
          wrote on last edited by
          #4

          @kshegunov

          Hi, friend. I work it out.

          Just to install libmysqlclient18 is ok.

          my way:

          1. download libmysqlclient18
          2. install it

          Just do it!

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved