Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved MYSQL driver not loaded when using mariadb on Debian Linux

    General and Desktop
    3
    7
    488
    Loading More Posts
    • 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.
    • T
      tataDanAz last edited by

      I am using Debian 10 (which by default comes with mariadb instead of mysql. I have the mariadb 10.3 client and 10.3 server installed and functioning. I installed QT 5.11.3 using the apt install command. My version of QT Creator is 4.8.2.
      The relevant code that I am using is:```
      void MainWindow::on_pushButton_clicked()
      {
      QSqlDatabase db = QSqlDatabase::addDatabase("MYSQL");
      db.setHostName("127.0.0.1");
      db.setUserName("root");
      db.setPassword("");
      db.setDatabaseName("nation");

      if (db.open()) {
          QMessageBox::information(this, "Connection", "Database Connected Successfully");
      } else{
          QMessageBox::information(this, "Not Connected", "Database Is Not Connected");
      }
      

      }

      The error that I get is :```
      QSqlDatabase: MYSQL driver not loaded
      QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3
      

      Any assistance in this matter would be appreciated.

      1 Reply Last reply Reply Quote 0
      • B
        Bonnie last edited by Bonnie

        I guess mariadb doesn't have libmysqlclient.so which is needed by the old pre-compiled mysql plugin?
        You can set QT_DEBUG_PLUGINS environment variable to 1 and check the diagnostic information from output.

        1 Reply Last reply Reply Quote 0
        • T
          tataDanAz last edited by

          libmysqlclient.so is in /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers, but it did not come the standard debian installation. I think it came from a ubuntu .deb file. Here is an extract of the output when application with QT_DEBUG_PLUGINS=1:

          code_QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers" ...
          QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so"
          "Failed to extract plugin meta data from '/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so'" 
                   not a plugin
          QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so"
          Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so, metadata=
          {
              "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
              "MetaData": {
                  "Keys": [
                      "QSQLITE"
                  ]
              },
              "className": "QSQLiteDriverPlugin",
              "debug": false,
              "version": 330499
          }
          
          
          Got keys from plugin meta data ("QSQLITE")
          QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so"
          Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so, metadata=
          {
              "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
              "MetaData": {
                  "Keys": [
                      "QMYSQL3",
                      "QMYSQL"
                  ]
              },
              "className": "QMYSQLDriverPlugin",
              "debug": false,
              "version": 330499
          }
          
          
          Got keys from plugin meta data ("QMYSQL3", "QMYSQL")
          QFactoryLoader::QFactoryLoader() checking directory path "/home/daniel/qtProjects/build-qt5database-Desktop-Debug/sqldrivers" ...text
          

          The most important piece of the output is:

          "Failed to extract plugin meta data from '/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libmysqlclient.so'" 
                   not a plugin
          

          Is it possible to find a valid version of libmysqlclient.so?

          jsulm B 2 Replies Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @tataDanAz last edited by jsulm

            @tataDanAz said in MYSQL driver not loaded when using mariadb on Debian Linux:

            libmysqlclient.so

            This is NOT Qt plug-in for MySql! This is the client library from MySql/MariaDB. Why is this file in /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers?!
            The correct file name of the plug-in should be libqsqlmysq.so

            Please search for MySQL in this forum: this is asked many many times and was answered many times.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 1
            • B
              Bonnie @tataDanAz last edited by

              @tataDanAz
              No, it is not the most important piece, just because libmysqlclient.so is not supposed to be put in the plugin folder.
              I think you should move it to the qt bin folder.
              The most important piece should be about libqsqlmysql.so.
              Is it loaded successfully? If not, what's the information?

              1 Reply Last reply Reply Quote 1
              • T
                tataDanAz last edited by

                @Bonnie said in MYSQL driver not loaded when using mariadb on Debian Linux:

                QT_DEBUG_PLUGINS

                Apparently in Debian libmysqlclient.so is a symbolic link to libmariadbclient.so (at least that's what my limited understanding leads me to believe).
                I copied both files from /usr/lib/x86_64-linux-gnu to /usr/lib/x86_64-linux-gnu/qt5/bin, but I still get the error. (I also tried copying them to /usr/lib/qt5/bin and the directory when my application resides, but that did not work either).
                As far as I can tell, libqsqlmysql.so loaded successfully. Here is the latest extract from the output:

                QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so"
                Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so, metadata=
                {
                    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
                    "MetaData": {
                        "Keys": [
                            "QMYSQL3",
                            "QMYSQL"
                        ]
                    },
                    "className": "QMYSQLDriverPlugin",
                    "debug": false,
                    "version": 330499
                }
                
                Got keys from plugin meta data ("QMYSQL3", "QMYSQL")
                
                QFactoryLoader::QFactoryLoader() checking directory path "/home/daniel/qtProjects/build-qt5database-Desktop-Debug/sqldrivers" ...
                QSqlDatabase: MYSQL driver not loaded
                QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3
                
                
                1 Reply Last reply Reply Quote 0
                • T
                  tataDanAz last edited by

                  I finally discovered the problem. It was a problem in my code.
                  Instead of writing

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

                  I wrote

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

                  I was attempting to enter the code from a youtube video and I left out a "Q".
                  Thanks to all who attempted to help me. I hope that I didn't cause anybody too much difficulty in trying to help me.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post