Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. MySQL driver isn't installed
Forum Updated to NodeBB v4.3 + New Features

MySQL driver isn't installed

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
15 Posts 4 Posters 1.5k 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.
  • P pierrbt

    Hi,
    I have installed a MySQL server on my computer few days ago and I'm actually trying to connect my application to that database. I tried to connect it but i saw that the QMySQL database type wasnt' installed. I tried to reinstall the "Connector C++" from MySQL website and tried some manipulations to make that function worked but it still doesn't work.

    Here is my code, hope you can solve my problem :

    QSqlDatabase Register::SQLConnection()
    {
    
        qDebug() << QSqlDatabase::drivers();
            if(!db.isValid()) {
                db = QSqlDatabase::addDatabase("QSQLITE");
    
    
                db.setHostName("localhost");
                db.setPort(3306);
                db.setDatabaseName("mysteriousdb");
                db.setUserName("root");
                db.setPassword("whoknows");
    
    
                QString opts = "QF_CODEC_NAME=cp1250;QF_MYSQL_SET_NAMES=latin1";
    
                qDebug() << "Connecting to " << db.connectionName() << " at "  << db.hostName() << "on the port " << db.port() <<  " as " << db.userName();
    
                db.setConnectOptions(opts);
    
                bool ok = db.open();
                
                qDebug() << db.driver();
    
                if(!ok) qCritical() << "ERROR open database:" << db.lastError().text();
                else {
    
                    qDebug() << "Connect successful";
                    QSqlQuery query = QSqlQuery(db);
                    QString sql;
                    sql += "SELECT * FROM users;";
                    
                            query.prepare(sql);
                            qDebug() << query.exec();
                            query.clear();
    
                }
            }
            
            return db;
    }
    
      pierrbt.
    

    Edit : I used QSQLITE to test if it was working but it doesn't, and here is the Application Output :

    QList("QSQLITE", "QODBC", "QPSQL")
    Connecting to  "qt_sql_default_connection"  at  "localhost" on the port  3306  as  "root"
    QSQLiteDriver(0x1d01f214a20)
    Connect successful
    false
    
    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @pierrbt said in MySQL driver isn't installed:

    QList("QSQLITE", "QODBC", "QPSQL")

    You do not have Qt MySQL plug-in installed.
    This plug-in is not delivered by default, you have to build it by yourself, see https://doc.qt.io/qt-5/sql-driver.html

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

    1 Reply Last reply
    2
    • P pierrbt

      Hi,
      I have installed a MySQL server on my computer few days ago and I'm actually trying to connect my application to that database. I tried to connect it but i saw that the QMySQL database type wasnt' installed. I tried to reinstall the "Connector C++" from MySQL website and tried some manipulations to make that function worked but it still doesn't work.

      Here is my code, hope you can solve my problem :

      QSqlDatabase Register::SQLConnection()
      {
      
          qDebug() << QSqlDatabase::drivers();
              if(!db.isValid()) {
                  db = QSqlDatabase::addDatabase("QSQLITE");
      
      
                  db.setHostName("localhost");
                  db.setPort(3306);
                  db.setDatabaseName("mysteriousdb");
                  db.setUserName("root");
                  db.setPassword("whoknows");
      
      
                  QString opts = "QF_CODEC_NAME=cp1250;QF_MYSQL_SET_NAMES=latin1";
      
                  qDebug() << "Connecting to " << db.connectionName() << " at "  << db.hostName() << "on the port " << db.port() <<  " as " << db.userName();
      
                  db.setConnectOptions(opts);
      
                  bool ok = db.open();
                  
                  qDebug() << db.driver();
      
                  if(!ok) qCritical() << "ERROR open database:" << db.lastError().text();
                  else {
      
                      qDebug() << "Connect successful";
                      QSqlQuery query = QSqlQuery(db);
                      QString sql;
                      sql += "SELECT * FROM users;";
                      
                              query.prepare(sql);
                              qDebug() << query.exec();
                              query.clear();
      
                  }
              }
              
              return db;
      }
      
        pierrbt.
      

      Edit : I used QSQLITE to test if it was working but it doesn't, and here is the Application Output :

      QList("QSQLITE", "QODBC", "QPSQL")
      Connecting to  "qt_sql_default_connection"  at  "localhost" on the port  3306  as  "root"
      QSQLiteDriver(0x1d01f214a20)
      Connect successful
      false
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #3

      @pierrbt
      If you are asking about QMYSQL plug-in then you must follow @jsulm's advice.

      If you are asking why your code shown using SQLite/QSQLITE appears to return false from query.exec("SELECT * FROM users;") there is a QSqlError QSqlQuery::lastError() const to call after the exec(). Maybe your database does not have any users table?

      piervalliP P 2 Replies Last reply
      0
      • JonBJ JonB

        @pierrbt
        If you are asking about QMYSQL plug-in then you must follow @jsulm's advice.

        If you are asking why your code shown using SQLite/QSQLITE appears to return false from query.exec("SELECT * FROM users;") there is a QSqlError QSqlQuery::lastError() const to call after the exec(). Maybe your database does not have any users table?

        piervalliP Offline
        piervalliP Offline
        piervalli
        wrote on last edited by
        #4

        @JonB PS For Mysql the connector is the "Connector C" not for c++. With 5.15.2 in window mysql driver is already builded, but if it not in the list you must be it by source code.

        1 Reply Last reply
        0
        • JonBJ JonB

          @pierrbt
          If you are asking about QMYSQL plug-in then you must follow @jsulm's advice.

          If you are asking why your code shown using SQLite/QSQLITE appears to return false from query.exec("SELECT * FROM users;") there is a QSqlError QSqlQuery::lastError() const to call after the exec(). Maybe your database does not have any users table?

          P Offline
          P Offline
          pierrbt
          wrote on last edited by pierrbt
          #5

          @JonB Ok i will try @jsulm advice but, according to me, the command don't work because I configured the plugin as a SQLite one, and the users table exists because i tried the same command in the main MySQL shell and it was working

          jsulmJ JonBJ 2 Replies Last reply
          0
          • P pierrbt

            @JonB Ok i will try @jsulm advice but, according to me, the command don't work because I configured the plugin as a SQLite one, and the users table exists because i tried the same command in the main MySQL shell and it was working

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @pierrbt said in MySQL driver isn't installed:

            I configured the plugin as a SQLite one, and the users table exists because i tried the same command in the main MySQL shell and it was working

            But did you create that table in your SQLite database?

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

            1 Reply Last reply
            0
            • P pierrbt

              @JonB Ok i will try @jsulm advice but, according to me, the command don't work because I configured the plugin as a SQLite one, and the users table exists because i tried the same command in the main MySQL shell and it was working

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #7

              @pierrbt

              @JonB said in MySQL driver isn't installed:

              there is a QSqlError QSqlQuery::lastError() const to call after the exec().

              ? What's the point of guessing if you have a call to use?

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pierrbt
                wrote on last edited by
                #8

                @jsulm I use a MySQL database and, yes i create it. And, it may seem like an obvious question but in the doc you send me, they said to execute a command, so i run that command on the Windows Command Prompt but it return an error :

                C:\Qt\6.2.3\Src>configure.bat -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY="C:\Program Files\MySQL \MySQL Connector C 6.1\lib\libmysql.lib
                +qtbase cd
                + C:\Qt\6.2.3\Src\qtbase\configure.bat -top-level -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY=" C:\Program Files\MySQL\MySQL Connector C 6.1\lib\libmysql.lib
                -top-level -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY="C:\Program Files\MySQL\MySQL Connector C 6.1\lib\libmysql. lib>config.opt.in
                'cmake' is not recognized as an internal command
                or external, an executable program or a batch file.
                'cmake' is not recognized as an internal command
                or external, an executable program or a batch file.
                

                And btw, here is the MySQL table config :

                alt text

                jsulmJ 1 Reply Last reply
                0
                • P pierrbt

                  @jsulm I use a MySQL database and, yes i create it. And, it may seem like an obvious question but in the doc you send me, they said to execute a command, so i run that command on the Windows Command Prompt but it return an error :

                  C:\Qt\6.2.3\Src>configure.bat -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY="C:\Program Files\MySQL \MySQL Connector C 6.1\lib\libmysql.lib
                  +qtbase cd
                  + C:\Qt\6.2.3\Src\qtbase\configure.bat -top-level -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY=" C:\Program Files\MySQL\MySQL Connector C 6.1\lib\libmysql.lib
                  -top-level -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY="C:\Program Files\MySQL\MySQL Connector C 6.1\lib\libmysql. lib>config.opt.in
                  'cmake' is not recognized as an internal command
                  or external, an executable program or a batch file.
                  'cmake' is not recognized as an internal command
                  or external, an executable program or a batch file.
                  

                  And btw, here is the MySQL table config :

                  alt text

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @pierrbt said in MySQL driver isn't installed:

                  'cmake' is not recognized as an internal command

                  You need cmake to build Qt6.

                  And I was refering to:
                  "I configured the plugin as a SQLite one, and the users table exists because i tried the same command in the main MySQL shell and it was working".
                  SQLite != MySQL
                  SQLite stores the database in a file, it has absolutelly nothing to do with MySQL.

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

                  1 Reply Last reply
                  1
                  • P Offline
                    P Offline
                    pierrbt
                    wrote on last edited by
                    #10

                    I've already installed CMake :

                    alt text

                    but it don't appear in the build options, have i need to build from a command prompt ?

                    And yes i know that MySQL != SQLite but i was just trying to test ...

                    jsulmJ 1 Reply Last reply
                    0
                    • P pierrbt

                      I've already installed CMake :

                      alt text

                      but it don't appear in the build options, have i need to build from a command prompt ?

                      And yes i know that MySQL != SQLite but i was just trying to test ...

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @pierrbt Make sure folder containing cmake executable is in path.
                      On Windows you also should execute batch script which prepares the build environment (it should be in the Qt start menu entry and in Qt installation folder). Which one depends on your compiler: either the one for MinGW or MSVC.

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

                      P 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @pierrbt Make sure folder containing cmake executable is in path.
                        On Windows you also should execute batch script which prepares the build environment (it should be in the Qt start menu entry and in Qt installation folder). Which one depends on your compiler: either the one for MinGW or MSVC.

                        P Offline
                        P Offline
                        pierrbt
                        wrote on last edited by pierrbt
                        #12

                        @jsulm I maybe found : i was coding my app in a "Empty qmake Project", it's maybe the reason why it wasn't working. I'm actually trying to copy the old scripts to the new Project.

                        EDIT : And by the way, which compiler should i use, MSVC, MinGW or WebAssembly @jsulm ?

                        jsulmJ 1 Reply Last reply
                        0
                        • P pierrbt

                          @jsulm I maybe found : i was coding my app in a "Empty qmake Project", it's maybe the reason why it wasn't working. I'm actually trying to copy the old scripts to the new Project.

                          EDIT : And by the way, which compiler should i use, MSVC, MinGW or WebAssembly @jsulm ?

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          @pierrbt said in MySQL driver isn't installed:

                          And by the way, which compiler should i use, MSVC, MinGW or WebAssembly @jsulm ?

                          That's up to you.
                          WebAssembly is for applications running in a browser.

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

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            pierrbt
                            wrote on last edited by pierrbt
                            #14

                            @jsulm Ok, i've finally installed CMake and the project is working, the MySQL plugin still doesn't work but it will be easier to repair it ( i hope ).

                            Here is my project :
                            alt text

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              pierrbt
                              wrote on last edited by
                              #15

                              @jsulm I finally fix my problem, I replaced lots of DLLs of the MySQL and MinGW folders using that repository and it finally work ! The MySQL Driver is detected by the compiler and I can perfectly use it. I tried to made that command :

                              INSERT INTO users (pseudo, mail, birthdate, passwd) 
                              VALUES ("pierrbt",
                                      "haha@gmail.com",
                                      "2000-01-01", 
                                      "testPassword");
                              

                              and it's working. Thanks for helping me to fix that problem.

                              1 Reply Last reply
                              1

                              • Login

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