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. Use QMysql driver on without having Mysql installed

Use QMysql driver on without having Mysql installed

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.0k Views
  • 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.
  • X Offline
    X Offline
    xhallix
    wrote on last edited by xhallix
    #1

    Hi,

    my database is served from a docker container, it's ports are forwarded to my host machine.
    Due to this setup, I do not have mysql installed on my machine.
    When trying to using

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("foobar");
    db.setUserName("root");
    db.setPassword("1234");
    

    I'm receiving QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

    I read that some libmysql*.dylib files are missing.

    Since I got no mysql, but mysql workbench installed I tried to copy them into the plugin directory of mysql where also the sqlite driver binaries reside.

    Unfortunately (oh so unexpected) this does not work.

    How can I get a mysql connection using QT without having mysql installed on the machine? (I'm on osx btw)

    *** edit ***
    my libary paths ("/Users/me/Qt/5.8/clang_64/plugins") includes libqsqlmysql.dylib, libqsqlmysql.dylib, libqsqlmysql_debug.dylib, libqsqlmysql_debug.dylib by default.

    sqlite worked like a charm

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Handling of dependencies on macOS is not the same at all as on Windows.

      For your problem, run otool -L libqsqlmysql.dylib. You'll see the list of the dependencies and where they are looked for. Use the install_name_tool command and update the path to where your MySQL client library can be found.

      As for SQLite, by default that plugin is built using Qt's own version of QSLite hence no external dependencies.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • X Offline
        X Offline
        xhallix
        wrote on last edited by xhallix
        #3

        Hi and thanks for trying to help me.
        It worked very well.
        Running this command outputs the following

        $ otool -L libqsqlmysql.dylib
        libqsqlmysql.dylib:
        	libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
        	@rpath/QtSql.framework/Versions/5/QtSql (compatibility version 5.8.0, current version 5.8.0)
        	@rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.8.0, current version 5.8.0)
        	/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
        	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
        	/opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
        	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
        	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
        	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
        
        

        for example when I lookup /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib it does not exists at all.

        Since I want no local mysql server , I installed it in a local brew folder, copied the .dylib in the directory I mentioned above and removed the mysql server in my local brew folder.
        Now, I am able to access the docker based mysql server without any issues.

        thanks for helping me.
        I had this issue once when building a plain c++ mysql connector on windows, but with this osx thing I was a bit lost at the beginning, so again big thanks :)

        best

        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