Use QMysql driver on without having Mysql installed
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");
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
I read that some
libmysql*.dylibfiles 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
sqlite worked like a charm
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_toolcommand 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.
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.dylibit does not exists at all.
Since I want no local mysql server , I installed it in a local brew folder, copied the
.dylibin 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 :)