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. [Windows] mysql compiled, available but not loaded
Qt 6.11 is out! See what's new in the release blog

[Windows] mysql compiled, available but not loaded

Scheduled Pinned Locked Moved General and Desktop
15 Posts 8 Posters 16.6k Views 1 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    Dear all,
    I compiled my mysql dll with msvc following the "manual":http://doc.trolltech.com/4.7/sql-driver.html#qmysql-for-mysql-4-and-higher:

    Dowloaded the Windows x86, 32bit ZIP Archive from "there

    ":http://www.mysql.com/downloads/mysql#

    Then launched the following command (path are a bit different than the official manual)

    @ cd %QTDIR%\src\plugins\sqldrivers\mysql
    qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\lib\libmysql.lib" mysql.pro
    nmake@

    I also recompiled QSQLITE, just to compare

    I copied C:\Mysql\lib\libmysql.dll next to qsqlmysql4.dll in %QTDIR%\plugins\sqldrivers

    Then when I launch my prog and I get:
    @Debug: qApp->libraryPaths() = C:/Qt/4.7-x86/plugins - E:/Dev/SQLMsvc/release
    Debug: QSqlDatabase::drivers() = QSQLITE
    QSqlDatabase:: QMYSQL driver not loaded
    QSqlDatabase:: available drivers; QSQLITE@

    My dll seems to be compiled correctly : I checked the registry and found my plugin in 4.7.false but not in 4.7
    !http://pix.wefrag.com/i/b/8/2/9/b/30861ba38bf6fb1520bc5388a58bd3a2.png(4.7)!
    !http://pix.wefrag.com/i/9/3/0/3/f/30862f931b965e38d385c6fbb096ee65.png(4.7.false)!

    So what is wrong with my sql plugin?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JulienMaille
      wrote on last edited by
      #2

      Ok, I moved libmysql.dll in my application directory and now I get: @Debug: qApp->libraryPaths() = C:/Qt/4.7-x86/plugins - E:/Dev/SQLMsvc/release
      Debug: QSqlDatabase::drivers() = QSQLITE - QMYSQL3 - QMYSQL
      Driver not loaded@ So, now the plugin is correcly found, but as soon as I create a new QSqlDatabase("QMYSQL") I get this Driver not loaded error.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        azr79
        wrote on last edited by
        #3

        I have the same probelm, can somebody help?

        Azr79

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sigrid
          wrote on last edited by
          #4

          Can you try setting your PATH environment variable to contain the path to libmysql.dll? It will not help to put libmysql.dll in your application directory or in the plugins directory. In case you don't want to change your environment variable, then you can instead try putting libmysql.dll in yourQtDirectory/bin together with the Qt dlls.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JulienMaille
            wrote on last edited by
            #5

            Where should I put libmysql.dll when redistributing my app?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              best would be to the directory of your binary (exe) file, as that is the first dir that windows scans for dlls.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Thoron
                wrote on last edited by
                #7

                Got the same problem, but nothing helps. I had QMYSQL driver listed as available, also I copied libmysql.dll to QtDir/bin and placed all mysql dlls in my library paths, but still receive:

                QSqlError(-1, "Driver not loaded", "Driver not loaded")

                Any other ideas? Now I'm considering use QODBC.

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  JulienMaille
                  wrote on last edited by
                  #8

                  Did you tried copying libmysql.dll next to your program exe?

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    Thoron
                    wrote on last edited by
                    #9

                    Yep, still nothing. BTW, it's one of my library paths. I tried even with different versions of MySQL Server (the same problems with 5.5 and 5.6).

                    1 Reply Last reply
                    0
                    • TheBadgerT Offline
                      TheBadgerT Offline
                      TheBadger
                      wrote on last edited by
                      #10

                      I do not have experience with MySQL but with PostgreSQL. From what I have found there is sometimes more than just the lib*sql.dll that the app needs to load before the plugin works. Get something like dependency walker and check what is needed by libmysql.dll and add all of those to the app dir, or just copy everything in the bin folder of MySQL into the app dir and check if that does not work.


                      Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        Thoron
                        wrote on last edited by
                        #11

                        Dependency walker has shown nothing additional stuff, so it's not it, but thank you for your hint. Well, I recompiled drivers once again and tried from scratch with most trivial database opening. The code is below.

                        @
                        QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
                        db.setHostName("mysql.agh.edu.pl");
                        db.setUserName("thoron");
                        db.setPassword("mypassword");
                        db.setPort(3306);
                        db.setDatabaseName("thoron");

                        if(db.open())
                        {
                            qDebug()<<"Database is open.";
                        }
                        else
                        {
                            qDebug()<<db.lastError();
                        }@
                        

                        What is interesting, that SQL drivers are loaded properly, but I receive error like this:

                        QSqlError(2003, "QMYSQL: Unable to connect", "Can't connect to MySQL server on 'mysql.agh.edu.pl' (10060)")

                        It seems to be sort of an error on the database site. However, I'm still getting it despite firewall being remotely closed. Database is on some mySQL server, not on my machine and I can access it by, for example php script. Do you have any hints on that?

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          JulienMaille
                          wrote on last edited by
                          #12

                          Are you sure this sql server allows connection from outside? I know it's not allowed on my webhost.
                          Try locally first to debug your code.

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            Thoron
                            wrote on last edited by
                            #13

                            It may be sort of this problem. I created mySQL database on my localhost and it can be reached from Qt without any issues. The previous database was off of my student account on my university, so maybe it's not allowed to reach from my machine. Anywa thank you guys for all guidance. I'm getting mad. :)

                            1 Reply Last reply
                            0
                            • francescmmF Offline
                              francescmmF Offline
                              francescmm
                              wrote on last edited by
                              #14

                              For me the solution was to put libmysql.dll into C:\Windows or in the $PATH variable. In addition I have also put qsqlmysql4.dll into a folder named "sqldrivers".

                              That folder is placed in the same place that the executable.

                              1 Reply Last reply
                              1
                              • D Offline
                                D Offline
                                dragonprince77
                                wrote on last edited by
                                #15

                                I tried putting libmysql.dll into C:\Windows (I am using Windows 7). I did not want to deal with the $PATH variable because that's solely in the command line and most of my directories are long filenames.

                                I put qsqlmysql.dll and qsqlmysqld.dll into a folder called sqldrivers in the %ProjectFolder%/Win32/Debug folder along w/ my executable so it's basically:

                                %ProjectFolder%
                                -Win32
                                --Debug
                                ---sqldrivers
                                ----qsqlmysql.dll
                                ----qsqlmysqld.dll

                                I have tried rebuilding the plugin, no use. Someone suggested it as a problem with the database but I had downloaded yesterday MySQL workbench from MYSQL and used that to create the first table of the application. I also (when I read that), went to eclipse and wrote a small application in Java to do the query I was trying to do to start with (basically the 'get all' atomic read function).

                                I'm so close to scrapping QT for SQL and just writing my own wrapper using MySQL itself but like the look of the API if it would JUST work!

                                1 Reply Last reply
                                0

                                • Login

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