Solved Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded
-
@Sunfluxgames , I copied:
libqsqlmysql.dylib
to:
~/build-SimonQtWidgets-Desktop_Qt_5_11_2_clang_64bit-Debug
The problem and reported errors haven't changed, still the same.
-
@SPlatten
I do not use Mac or compile Qt.But it seems to me that the error message:
Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
is unequivocal. You need a
libmysqlclient.20.dylib
. (Moving justlibqsqlmysql.dylib
to somewhere is not going to address this.)Try Googling for
libqsqlmysql
. There are others asking about this being missing under Linux/MacOS. You may need to download it (apt-get
under MacOS? I have no idea) given what you show from yourfind
and/or see e.g. https://afshinm.name/2016/02/05/how-to-fix-library-not-loaded-libmysqlclient-18-dylib-in-mac-os-x/ -
~/Qt/5.11.2/clang_64/bin/qmake "INCLUDEPATH += /usr/local/mysql/include/" "LIBS += -L/usr/local/mysql/" mysql.pro
Complie mysql.pro in qtbase/sqldrivers
And then:
cp ~/Qt/5.11.2/Src/qtbase/plugins/sqldrivers/ ~/Qt/5.11.2/clang_64/plugins/sqldrivers/
Also might need to copy them to the creator folder as well to debug inside creator.
-
@Sunfluxgames , there i no /usr/local/mysql folder on my system, its MariaDB, when I ran:
~./Qt/5.11.2/clang_64/bin/qmake "INCLUDEPATH += /usr/local/mysql/include/" "LIBS += -L/usr/local/mysql/" mysql.pro
I got:
Cannot find file: mysql.pro.
-
Before trying to build anything (you need to first download the sources for that). Please run your application with the
QT_DEBUG_PLUGINS
environment variable set to 1.Click on the Project button on the vertical toolbar on the left of Qt Creator, and there you'll find the Build and Run settings. Modify the Environment in the Run settings.
-
@SGaist , I did that, hasn't helped.
-
It's not supposed to change anything in the application execution. The goal is to provide you with additional information about what is happening when plugins are getting or not loaded and from there help find what might be going wrong.
-
@SGaist said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:
QT_DEBUG_PLUGINS
With QT_DEBUG_PLUGINS added to the environment the output when single stepping over:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
Is:
2018-10-11 08:28:13.253913+0100 SimonQtWidgets[1031:41669] Got keys from plugin meta data ("QPSQL7", "QPSQL") 2018-10-11 08:28:13.253927+0100 SimonQtWidgets[1031:41669] QFactoryLoader::QFactoryLoader() checking directory path "/Users/simonplatten/build-SimonQtWidgets-Desktop_Qt_5_11_2_clang_64bit-Debug/SimonQtWidgets.app/Contents/MacOS/sqldrivers" ... 2018-10-11 08:28:13.255823+0100 SimonQtWidgets[1031:41669] Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib Reason: image not found) 2018-10-11 08:28:13.255844+0100 SimonQtWidgets[1031:41669] QLibraryPrivate::loadPlugin failed on "/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib\n Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib\n Reason: image not found)" 2018-10-11 08:28:13.255 859+0100 SimonQtWidgets[1031:41669] QSqlDatabase: QMYSQL driver not loaded 2018-10-11 08:28:13.255885+0100 SimonQtWidgets[1031:41669] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
-
@SPlatten said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:
Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
Do you have this lib in that location?
-
@jsulm , No, I've no idea what this library is or where is comes from. The path /usr/local/mysql doesn't exist.
-
@SPlatten This is the MySQL client library which is used by Qt to access MySQL databases. You need it if you want to use MySQL.
-
@jsulm said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:
libmysqlclient.20.dylib
I've found what I think is the correct library on my system:
/usr/local/Cellar/mariadb/10.2.6/lib/libmariadb.dylib
I then tried:
sudo ln -s /usr/local/Cellar/mariadb/10.2.6/lib/libmariadb.dylib /usr/local/lib/libmysqlclient.20.dylib
Re-ran in debug and the problem has changed, looks like I'm using the wrong library now:
2018-10-11 09:15:08.331712+0100 SimonQtWidgets[1644:135071] Got keys from plugin meta data ("QPSQL7", "QPSQL") 2018-10-11 09:15:08.331726+0100 SimonQtWidgets[1644:135071] QFactoryLoader::QFactoryLoader() checking directory path "/Users/simonplatten/build-SimonQtWidgets-Desktop_Qt_5_11_2_clang_64bit-Debug/SimonQtWidgets.app/Contents/MacOS/sqldrivers" ... 2018-10-11 09:15:08.347152+0100 SimonQtWidgets[1644:135071] Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib Reason: Incompatible library version: libqsqlmysql.dylib requires version 20.0.0 or later, but libmysqlclient.20.dylib provides version 3.0.0) 2018-10-11 09:15:08.347182+0100 SimonQtWidgets[1644:135071] QLibraryPrivate::loadPlugin failed on "/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib\n Referenced from: /Users/sim onplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib\n Reason: Incompatible library version: libqsqlmysql.dylib requires version 20.0.0 or later, but libmysqlclient.20.dylib provides version 3.0.0)" 2018-10-11 09:15:08.347201+0100 SimonQtWidgets[1644:135071] QSqlDatabase: QMYSQL driver not loaded 2018-10-11 09:15:08.347228+0100 SimonQtWidgets[1644:135071] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
-
Don't use
ln
that won't help, useinstall_name_tool
and update the path in libqsqlmysql.dylib to match what you have on your system. -
@SGaist, thank you, do you have an example? How do I achieve this?
-
Did you read the tool's help ?
install_name_tool -change /usr/local/mysql/lib/libmysqlclient.20.dylib /path/to/mariadb/libmariadbclient.X.dylib /Users/hasan/Qt5.9.1/5.9.1/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
Note that MariaDB should be a drop-in replacement however I haven't tried to "re-link" to a library that has different name (just a different compatible version number) so you may have other surprises.
-
@SPlatten said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:
2018-10-11 09:15:08.331712+0100 SimonQtWidgets[1644:135071] Got keys from plugin meta data ("QPSQL7", "QPSQL")
2018-10-11 09:15:08.331726+0100 SimonQtWidgets[1644:135071] QFactoryLoader::QFactI'm struggling, the only libmariadbclient I can find on my entire system is:
/usr/local/Cellar/mariadb/10.2.6/lib/libmariadbclient.a
-
Then that's something you have to check with the brew folks.
-
@SGaist , I was looking for an .so library, I've now learnt that a .dylib is the mac os equivalent.
The database I'm using is MariaDB, I've just updated this using:
brew upgrade mariadb
Then:
brew services restart mariadb
This has added:
/usr/local/Cellar/mariadb/10.3.10/lib
Containing:
-rwxr-xr-x 1 simonplatten staff 1425020 13 Sep 05:40 libqsqlite.dylib drwxr-xr-x 3 simonplatten staff 96 4 Oct 13:26 libqsqlite.dylib.dSYM -rwxr-xr-x 1 simonplatten staff 1435972 13 Sep 05:38 libqsqlite_debug.dylib drwxr-xr-x 3 simonplatten staff 96 4 Oct 13:26 libqsqlite_debug.dylib.dSYM -rwxr-xr-x 1 simonplatten staff 79864 13 Sep 05:40 libqsqlmysql.dylib drwxr-xr-x 3 simonplatten staff 96 4 Oct 13:26 libqsqlmysql.dylib.dSYM -rwxr-xr-x 1 simonplatten staff 137448 13 Sep 05:38 libqsqlmysql_debug.dylib drwxr-xr-x 3 simonplatten staff 96 4 Oct 13:26 libqsqlmysql_debug.dylib.dSYM -rwxr-xr-x 1 simonplatten staff 88980 13 Sep 05:40 libqsqlpsql.dylib drwxr-xr-x 3 simonplatten staff 96 4 Oct 13:26 libqsqlpsql.dylib.dSYM -rwxr-xr-x 1 simonplatten staff 138612 13 Sep 05:38 libqsqlpsql_debug.dylib drwxr-xr-x 3 simonplatten staff 96 4 Oct 13:26 libqsqlpsql_debug.dylib.dSYM
Looking at the debug output from the Application Output:
2018-10-12 02:33:13.197110+0100 SimonQtWidgets[6965:134266] Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib Reason: image not found)
Why is it trying to load libmysqlclient.20.dylib ?
The next line in the Application output:
2018-10-12 02:33:13.197133+0100 SimonQtWidgets[6965:134266] QLibraryPrivate::loadPlugin failed on "/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/
Then:
(dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib\n Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib\n Reason: image not found)" 2018-10-12 02:33:13.1 97150+0100 SimonQtWidgets[6965:134266] QSqlDatabase: QMYSQL driver not loaded
-
@SPlatten said in Qt5.11.2, QSqlDatabase, QMYSQL, Driver not loaded:
libmysqlclient.20.dylib
@SGaist , I managed to progress the issue, this is what I did:
Manually create the required folder structure, from /usr/local:
sudo mkdir mysql cd mysql sudo mkdir lib cd lib
Then create a symbolic link to the required library:
sudo ln -s /usr/local/lib/libmysqlclient.dylib /usr/local/mysql/lib/libmysqlclient.20.dylib
Now debugging the same project, the call to open still fails with:
2018-10-12 08:44:19.696706+0100 SimonQtWidgets[1253:117317] loaded library "/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib" 2018-10-12 08:44:39.663805+0100 SimonQtWidgets[1253:117317] QSqlError("1130", "QMYSQL: Unable to connect", "Host '192.168.1.158' is not allowed to connect to this MariaDB server") 2018-10-12 08:44:40.409469+0100 SimonQtWidgets[1253:117317] Failed to connect.
Now resolved, the issue here was that the call to setHostName was using the host name of the system, I changed this to localhost and now everything works.
-
That shouldn't be necessary but at least it got you going further.
As for your second error, this is your database configuration you have to inspect.
Is it a remote machine ? If not then replace the host name with
localhost
and try again.