QMYSQL driver not loaded on Ubuntu
-
Hello:) Sorry for my English if I will make mistakes.
I have this error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.My code:
#include <iostream> #include <string> #include <QtSql> #include <QDebug> #include <QTableView> #include <QApplication> using namespace std; int main(int f, char** s) { QApplication app(f,s); QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setDatabaseName("test"); db.setUserName("urik"); db.setHostName("localhost:3306"); db.setPassword(""); if (db.open()) cout <<"Db is opened"; else cout <<db.lastError().text().toStdString(); db.close(); db.removeDatabase(db.connectionName()); app.exec(); }
I read this topic here .
But I don't have folder "/Src/qtbase/src/plugins/sqldrivers/mysql" as user from topic, therefore I don't know what should I do next.How to correctly install the driver for Mysql in my case? Thanks!
P.s. I have Qt 5.5 -
Hi and welcome to devnet,
To get the Src folder you have to install the sources using the maintenance tool.
One thing to check: do you have MySQL installed ? If so which version ?
-
@SGaist Version 5.6
urik@urik-HP-250-G1-Notebook-PC:~$ sudo dpkg --list|grep mysql
ii libdbd-mysql-perl 4.028-2 amd64 Perl5 database interface to the MySQL database
ii libmysqlclient18:amd64 5.6.28-0ubuntu0.15.04.1 amd64 MySQL database client library
ii libmysqlclient18:i386 5.6.28-0ubuntu0.15.04.1 i386 MySQL database client library
ii libmysqlcppconn7 1.1.3-6 amd64 MySQL Connector for C++ (library)
ii libqt4-sql-mysql:amd64 4:4.8.6+git64-g5dc8b2b+dfsg-3~ubuntu6.1 amd64 Qt 4 MySQL database driver
ii libqt4-sql-mysql:i386 4:4.8.6+git64-g5dc8b2b+dfsg-3~ubuntu6.1 i386 Qt 4 MySQL database driver
ii libqt5sql5-mysql:amd64 5.4.1+dfsg-2ubuntu4.1 amd64 Qt 5 MySQL database driver
ii mysql-client-5.6 5.6.28-0ubuntu0.15.04.1 amd64 MySQL database client binaries
ii mysql-client-core-5.6 5.6.28-0ubuntu0.15.04.1 amd64 MySQL database core client binaries
ii mysql-common 5.6.28-0ubuntu0.15.04.1 all MySQL database common files, e.g. /etc/mysql/my.cnf
ii mysql-server 5.6.28-0ubuntu0.15.04.1 all MySQL database server (metapackage depending on the latest version)
ii mysql-server-5.6 5.6.28-0ubuntu0.15.04.1 amd64 MySQL database server binaries and system database setup
ii mysql-server-core-5.6 5.6.28-0ubuntu0.15.04.1 amd64 MySQL database server binaries
ii mysql-utilities 1.3.5-2 all collection of scripts for managing MySQL servers
ii mysql-workbench 6.2.3+dfsg-7build1 amd64 MySQL Workbench - a visual database modeling, administration and queuing tool
ii mysql-workbench-data 6.2.3+dfsg-7build1 all MySQL Workbench -- architecture independent data
ii python-mysql.connector 1.2.3-2 all pure Python implementation of MySQL Client/Server protocolI have the same mistake like user from topic (Ihttps://forum.qt.io/topic/36072/solved-qmysql-driver-not-loaded-on-ubuntu/19):
@libmysqlclient_r.so.16 => not found@Please, tell me, where can I read about the installation the maintenance tool?
-
The maintenance tool executable can be found in your Qt installation, just start it, the rest is straight forward.
-
@SGaist Thanks.
I made so.
urik@urik-HP-250-G1-Notebook-PC:~/Qt/5.5/Src/qtbase/src/plugins/sqldrivers/mysql$ /home/urik/Qt/5.5/gcc_64/bin/qmake “INCLUDEPATH+=/usr/include/mysql” “LIBS+=-I/usr/lib/mysql” mysql.pro
urik@urik-HP-250-G1-Notebook-PC:~/Qt/5.5/Src/qtbase/src/plugins/sqldrivers/mysql$ make
rm -f libqsqlmysql.so
g++ -Wl,--no-undefined -Wl,-O1 -Wl,--enable-new-dtags -Wl,-rpath,/home/urik/Qt/5.5/gcc_64 -Wl,-rpath,/home/urik/Qt/5.5/gcc_64 -Wl,-rpath,/home/urik/Qt/5.5/gcc_64/lib -shared -o libqsqlmysql.so .obj/main.o .obj/qsql_mysql.o .obj/moc_qsql_mysql_p.o -rdynamic -L/usr/lib64/mysql -lmysqlclient_r -lz -lcrypt -lnsl -lm -lssl -lcrypto -L/home/urik/Qt/5.5/gcc_64/lib -lQt5Sql -lQt5Core -lpthread
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit statusurik@urik-HP-250-G1-Notebook-PC:~/Qt/5.5/Src/qtbase/src/plugins/sqldrivers/mysql$ sudo apt-get install libssl-dev
urik@urik-HP-250-G1-Notebook-PC:~/Qt/5.5/Src/qtbase/src/plugins/sqldrivers/mysql$ make
urik@urik-HP-250-G1-Notebook-PC:~$ sudo ld /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so
ld: warning: libmysqlclient_r.so.16, needed by /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so, not found (try using -rpath or -rpath-link)
ld: warning: libssl.so.10, needed by /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so, not found (try using -rpath or -rpath-link)
ld: warning: libcrypto.so.10, needed by /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so, not found (try using -rpath or -rpath-link)
ld: warning: cannot find entry symbol _start; not setting start address
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_select_db@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_options@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_real_query@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_stmt_data_seek@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_affected_rows@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_stmt_error@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_stmt_reset@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_data_seek@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_fetch_row@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_stmt_bind_result@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_real_connect@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_thread_end@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_stmt_fetch@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_stmt_bind_param@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_field_seek@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_stmt_execute@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_num_rows@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_list_tables@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_stmt_result_metadata@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
QString::simplified_helper(QString const&)'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_field_count@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_insert_id@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_stmt_attr_set@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_fetch_field_direct@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_stmt_store_result@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_get_client_version@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_stmt_param_count@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_get_server_version@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_query@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_stmt_prepare@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_stmt_affected_rows@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_list_fields@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_fetch_field@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_server_init@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference toQMetaType::registerNormalizedType(QByteArray const&, void (*)(void*), void* (*)(void*, void const*), int, QFlags<QMetaType::TypeFlag>, QMetaObject const*)' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_stmt_num_rows@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference toQString::simplified_helper(QString&)' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_real_escape_string@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_stmt_close@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_stmt_insert_id@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_error@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_server_end@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_set_character_set@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_stmt_init@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_stmt_errno@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_fetch_lengths@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_errno@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_next_result@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_store_result@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_close@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_free_result@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_init@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference tomysql_character_set_name@libmysqlclient_16' /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to
mysql_thread_init@libmysqlclient_16'
/home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so: undefined reference to `mysql_num_fields@libmysqlclient_16' -
You need to install the missing dev packages on your system
-
Sorry, I missed that you already installed libssl-dev after the first failure.
Looks like you forgot to call
make install
once the build finished. -
@SGaist Thanks! make install had helped me! But in my console had appeared these messages:
urik@urik-HP-250-G1-Notebook-PC:~/Qt/5.5/Src/qtbase/src/plugins/sqldrivers/mysql$ sudo ld /home/urik/Qt/5.5/gcc_64/plugins/sqldrivers/libqsqlmysql.so
ld: warning: libicui18n.so.54, needed by /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
ld: warning: libicuuc.so.54, needed by /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
ld: warning: libicudata.so.54, needed by /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
ld: warning: cannot find entry symbol _start; not setting start address
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucnv_countAvailable_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucal_open_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference tou_errorName_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucal_openCountryTimeZones_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucal_getDSTSavings_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucol_getSortKey_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucnv_countAliases_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucol_open_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucnv_open_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucal_close_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucal_setMillis_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
uenum_close_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucnv_getDefaultName_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucnv_getAlias_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference touenum_next_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucnv_getMaxCharSize_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucol_strcoll_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
u_strToLower_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucnv_getAvailableName_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucal_getDefaultTimeZone_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucal_getTimeZoneDisplayName_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
u_strToUpper_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucnv_toUnicode_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucal_openTimeZones_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucnv_getStandardName_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucol_close_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucal_clone_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucnv_close_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucol_setAttribute_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucnv_setSubstChars_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucal_openTimeZoneIDEnumeration_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucnv_fromUnicode_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference toucal_get_54' /home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to
ucal_inDaylightTime_54'
/home/urik/Qt/5.5/gcc_64/lib/libQt5Core.so.5: undefined reference to `ucnv_compareNames_54' -
Do you have these libraries in your Qt installation ?
-
First, search in Qt's installation folder
In any case, did you get the plugin to load ?