QMYSQL driver not loaded. available drivers: QSQLITE , QMYSQL , QMYSQL3
-
Before anyone says search the forums, I've seen lots of similar posts but none seemed to match my problem.
I am building an app in Qt5/C++ (using QtCreateor with Qt6 installed too) on Kubuntu 20 using QSqlDatabase. On execution the app complains about a missing MySQL driver:
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
I've installed every mysql/mariadb package that seems relevant:
apt list --installed | grep -i mysql libdbd-mysql-perl/kinetic,now 4.050-5 amd64 [installed,automatic] libmysqlclient21/kinetic-updates,kinetic-security,now 8.0.32-0ubuntu0.22.10.2 amd64 [installed] libqt5sql5-mysql/kinetic,now 5.15.6+dfsg-1 amd64 [installed] mysql-common/kinetic,kinetic,now 5.8+1.0.8 all [installed,automatic] apt list --installed | grep -i maria libmariadb-dev-compat/kinetic-updates,kinetic-security,now 1:10.6.12-0ubuntu0.22.10.1 amd64 [installed] libmariadb-dev/kinetic-updates,kinetic-security,now 1:10.6.12-0ubuntu0.22.10.1 amd64 [installed] libmariadb3/kinetic-updates,kinetic-security,now 1:10.6.12-0ubuntu0.22.10.1 amd64 [installed] mariadb-client-10.6/kinetic-updates,kinetic-security,now 1:10.6.12-0ubuntu0.22.10.1 amd64 [installed,automatic] mariadb-client-core-10.6/kinetic-updates,kinetic-security,now 1:10.6.12-0ubuntu0.22.10.1 amd64 [installed,automatic] mariadb-common/kinetic-updates,kinetic-updates,kinetic-security,kinetic-security,now 1:10.6.12-0ubuntu0.22.10.1 all [installed,automatic] mariadb-server-10.6/kinetic-updates,kinetic-security,now 1:10.6.12-0ubuntu0.22.10.1 amd64 [installed,automatic] mariadb-server-core-10.6/kinetic-updates,kinetic-security,now 1:10.6.12-0ubuntu0.22.10.1 amd64 [installed,automatic] mariadb-server/kinetic-updates,kinetic-updates,kinetic-security,kinetic-security,now 1:10.6.12-0ubuntu0.22.10.1 all [installed]
and ldd say my app can find libQt5Sql:
ldd myapp linux-vdso.so.1 (0x00007ffd311f7000) libQt5Network.so.5 => /opt/Qt/5.15.2/gcc_64/lib/libQt5Network.so.5 (0x00007f37fc600000) libQt5Sql.so.5 => /opt/Qt/5.15.2/gcc_64/lib/libQt5Sql.so.5 (0x00007f37fc200000) libQt5Core.so.5 => /opt/Qt/5.15.2/gcc_64/lib/libQt5Core.so.5 (0x00007f37fba00000) libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f37fb600000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f37fcae8000)
My Qt Creator was installed from binaries (from Qt site). So I don't think I should need to compile anything from source (and I've seen conflicting advice on SO about compile MySQL drives from source for Qt). I checked that libqsqlmysql.so has all dependencies:
ldd /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so linux-vdso.so.1 (0x00007ffef93fc000) libQt5Sql.so.5 => /lib/x86_64-linux-gnu/libQt5Sql.so.5 (0x00007f07d14f3000) libQt5Core.so.5 => /lib/x86_64-linux-gnu/libQt5Core.so.5 (0x00007f07d0e00000) libmysqlclient.so.21 => /lib/x86_64-linux-gnu/libmysqlclient.so.21 (0x00007f07d0600000) libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f07d0200000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f07cfe00000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f07d14d5000) libdouble-conversion.so.3 => /lib/x86_64-linux-gnu/libdouble-conversion.so.3 (0x00007f07d14c1000) libicui18n.so.71 => /lib/x86_64-linux-gnu/libicui18n.so.71 (0x00007f07cfa00000) libicuuc.so.71 => /lib/x86_64-linux-gnu/libicuuc.so.71 (0x00007f07d0005000) libpcre2-16.so.0 => /lib/x86_64-linux-gnu/libpcre2-16.so.0 (0x00007f07d1433000) libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f07d1384000) libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f07d0cc7000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f07d0517000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f07d1362000) /lib64/ld-linux-x86-64.so.2 (0x00007f07d1561000) libssl.so.3 => /lib/x86_64-linux-gnu/libssl.so.3 (0x00007f07d0472000) libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x00007f07cf400000) libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f07d0cb4000) libicudata.so.71 => /lib/x86_64-linux-gnu/libicudata.so.71 (0x00007f07cd600000) libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f07cfd65000)
Can someone tell me what's wrong here?
-
@ocgltd said in QMYSQL driver not loaded. available drivers: QSQLITE , QMYSQL , QMYSQL3:
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
Can someone tell me what's wrong here?
You did not install (or build,
don't know if your distribution provides a package) the qt mysql plugin./edit: since you seem to have installed Qt through the online installer you have to build the mysql plugin by yourself: https://doc.qt.io/qt-5/sql-driver.html
-
@Christian-Ehrlicher Can you tell me how to install it? Do you mean I need to run the Qt maintenance tool and pick something? There's so much generic advice...I just can't figure out exactly what to do
-
@ocgltd see my /edit comment
-
I ran the qmake statement, then make managed to get as far as:
cd mysql/ && ( test -e Makefile || /opt/Qt/6.4.1/gcc_64/bin/qmake -o Makefile /opt/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/mysql/mysql.pro ) && make -f Makefile make[1]: Entering directory '/opt/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/mysql' g++ -c -pipe -O2 -g -std=c++1z -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wall -Wextra -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -Wno-stringop-overflow -Wno-format-overflow -Wsuggest-override -D_REENTRANT -fPIC -DQT_NO_JAVA_STYLE_ITERATORS -DQT_DEPRECATED_WARNINGS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -I/opt/Qt/6.4.1/gcc_64/include/QtSql/6.4.1 -I/opt/Qt/6.4.1/gcc_64/include/QtSql/6.4.1/QtSql -I/opt/Qt/6.4.1/gcc_64/include/QtCore/6.4.1 -I/opt/Qt/6.4.1/gcc_64/include/QtCore/6.4.1/QtCore -I/opt/Qt/6.4.1/gcc_64/include -I/opt/Qt/6.4.1/gcc_64/include/QtSql -I/opt/Qt/6.4.1/gcc_64/include/QtCore -I.moc -I/usr/include/mariadb -I/usr/include/mariadb/mysql -I/opt/Qt/6.4.1/gcc_64/mkspecs/linux-g++ -o .obj/qsql_mysql.o qsql_mysql.cpp In file included from /opt/Qt/6.4.1/gcc_64/include/QtCore/qglobal.h:36, from /opt/Qt/6.4.1/gcc_64/include/QtSql/qtsqlglobal.h:7, from /opt/Qt/6.4.1/gcc_64/include/QtSql/qsqldriver.h:7, from qsql_mysql_p.h:54, from qsql_mysql.cpp:40: /opt/Qt/6.4.1/gcc_64/include/QtCore/qtconfigmacros.h:41:30: error: division by zero in #if 41 | #define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1) | ^ qsql_mysql.cpp:51:5: note: in expansion of macro ‘QT_CONFIG’ 51 | #if QT_CONFIG(textcodec) | ^~~~~~~~~ qsql_mysql.cpp:52:10: fatal error: qtextcodec.h: No such file or directory 52 | #include <qtextcodec.h> | ^~~~~~~~~~~~~~ compilation terminated. make[1]: *** [Makefile:1109: .obj/qsql_mysql.o] Error 1 make[1]: Leaving directory '/opt/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/mysql' make: *** [Makefile:48: sub-mysql-make_first] Error 2 root@vm-kubuntu20:/opt/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers#
-
Why you're on Qt6.4 suddenly? Please stay consistent! Then you have to follow the Qt6 documentation: https://doc.qt.io/qt-6/sql-driver.html and start over with a clean source dir!
-
@Christian-Ehrlicher I am using Qt 5.12.2 kit (though Qt6 is also installed).
I tried the Qt6 instructions and got stuck at
Tell qt-cmake where to find the MySQL / MariaDB header files and shared libraries (here it is assumed that MySQL / MariaDB is installed in /usr/local) and build:
I'm not sure where MySQL/MariaDB headers and libraries are installed, but there is nothing like that under /usr/local. Wondering if there is another step required
-
Hi,
Let's take a step back.
You are checking your distribution provided Qt which has everything it needs (and provides a more recent version of Qt).
Do you have a specific requirement to use an older version of Qt ?
That said, you seem to have the MariaDB dev package installed so you should of the required files. If you can't find them, check the archive content to see where they were installed.
Since you want to use Qt 5, please let Qt 6 for another time.
-
@SGaist I need to use Qt5 for backward compatibility with older Linux OS's.
I have removed "Qt6" using the maintenance tool in case that helps. The kit I have always selected for my project is Qt5.15.2
I think I've got everything right, yet the error persists. I don't understand how to move forward.
Using ldd $(find / -name "libqsqlmysql.so") indicates that all libraries are found.
I confirmed that ldconfig can find the libraries too:
ldconfig -p | grep sql libsqlite3.so.0 (libc6,x86-64) => /lib64/libsqlite3.so.0 libqsqlpsql.so (libc6,x86-64) => /opt/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlpsql.so libqsqlodbc.so (libc6,x86-64) => /opt/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlodbc.so libqsqlmysql.so (libc6,x86-64) => /opt/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlmysql.so libqsqlite.so (libc6,x86-64) => /opt/Qt/5.15.2/gcc_64/plugins/sqldrivers/libqsqlite.so libmysqlclient.so.21 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.21
And just in case it's a code problem, here's my code:
m_mySqlDbPtr = new QSqlDatabase(); m_mySqlDbPtr->addDatabase("QMYSQL"); m_mySqlDbPtr->setHostName(hostName); m_mySqlDbPtr->setUserName(username); m_mySqlDbPtr->setPassword(password); m_mySqlDbPtr->setPort(hostPort); m_mySqlDbPtr->setDatabaseName(database);
-
-
@ocgltd said in QMYSQL driver not loaded. available drivers: QSQLITE , QMYSQL , QMYSQL3:
m_mySqlDbPtr = new QSqlDatabase();
This is wrong, please read the documentation on how to use a QSqlDatabase! Do not create them on the heap!
-
@ocgltd said in QMYSQL driver not loaded. available drivers: QSQLITE , QMYSQL , QMYSQL3:
@ocgltd Wow..I solved it. The syntax for creating the QSqlDatabase is incorrect.
Once fixed it has not trouble connecting.
What a horrible error message for this! Wasted 7 hours.Nothing at all in what you showed, being compilation/linker messages, is related to this.