Yet *another* MYSQL drivers not loaded issue
Hi,
I've installed Qt 4.7.2 using the QtSDK installer, and I don't know how to get Qt to build/load the MySQL driver, which i need. I didn't see any config file in the QtSDK directory, and there's no such options given by the wizard. So ./configure -qt-sql-mysql isn't an option, and this thread
http://www.qtcentre.org/threads/3401...t-loaded-issue
didn't help me either. How can I get the driver? (I'm currently getting the 'QSqlDatabase: QMYSQL driver not loaded' error.)
Re: Yet *another* MYSQL drivers not loaded issue
Do you have MySQL client libraries installed?
Re: Yet *another* MYSQL drivers not loaded issue
Yes, should have mentioned that. I have a MySQL database that I can access perfectly well through the Query Browser and via PHP (phpMyAdmind or my own scripts).
Edit: I've also now tried to install support for mysql with the traditional ./configure method on an installation of 4.7.2 that I downloaded without the installer (creates the folder qt-everywhere-opensource-src-4.7.2). Trying to configure with -qt-sql-mysql, it stops halfway through and gives me this:
Quote:
MySQL support cannot be enabled due to functionality tests!
...
If you believe this message is in error you may use the continue
switch (-continue) to ./configure to continue.
When I continue, the installation completes but I still don't have MySQL support.
Re: Yet *another* MYSQL drivers not loaded issue
What is the path to MySQL client library?
Re: Yet *another* MYSQL drivers not loaded issue
Wysota,
I can't find libmyqslclient.so, which a little googling suggested is the relevant library. It's not in /usr or /etc. gives me
Quote:
mysql: /usr/bin/mysql /etc/mysql /usr/lib/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
In /usr/lib/mysql/plugin and /usr/lib/mysql/plugin I have ha_innodb_plugin.so.
The MySQL administrator says the socket for the server instance (which is running) is /var/run/mysqld/mysqld.sock, if that helps.
Re: Yet *another* MYSQL drivers not loaded issue
Without libmysqlclient.so you can't access MySQL databases. When I was asking if you had it installed you said yes. So decide whether you have mysql client libraries installed or not. If not then install them.
Re: Yet *another* MYSQL drivers not loaded issue
Hmm, it's not really a 'decision' is it... I wasn't sure whether I had the client libraries installed or not, since I have the MySQL server running and perfectly accessible through other means, in the Ubuntu software center MySQL Client is marked as 'installed', and I haven't had this problem in the past (I've mysql via previous versions of Qt, perhaps on a different version of Ubuntu--I can't be sure). Anyway, I found a package which put libmysqlclient.so.15 and *.16 in /usr/lib. I restarted but Qt still didn't see MySQL.
Edit: If I try to #include <QMYSQLDriver>, I get 'mysql.h: no such file or directory', deriving from
in qsql_mysql.h. Subsequent searching for mysql.h in the file system didn't turn up anything.
Edit 2: I now have mysql.h in /usr/include/mysql, and the path added to INCLUDEPATH in my .pro file. Also libmysqlclient.a in /usr/lib, and similarly
Quote:
LIBS += -L/usr/lib -lmysqlclient
Still 'mysql driver not loaded'.
Edit 3: So now, I tried to install 4.7.2 from the .tar file with configure options -static -release -qt-sql-mysql. It configured ok and then about an hour into the make, failed with
Quote:
In function 'global constructors keyed to main':
main.cpp: (.text+0x1): undefined reference to 'qt_plugin_instance_qsqlite()'
Re: Yet *another* MYSQL drivers not loaded issue
Why would you try to include QMYSQLDriver?
For MySQL plugin to work you need:
1. MySQL client library called "mysqlclient"
2. Qt MySQL plugin which either is already built and ready or to build it you need:
a) Qt source code
b) MySQL development files (headers)
c) MySQL client library (called "mysqlclient")
... and possibly dependencies of any of those. In addition to that if you run Windows you need to make sure you build the plugin in the appropriate mode (debug vs release).
Re: Yet *another* MYSQL drivers not loaded issue
Ok so I rebuilt 4.7.2 from the .tar file but this time without the -static option, as some searching indicated that sqlite was incompatible with a static build. After doing this, the mysql drivers were available with that version of Qt (hooray!). So clearly all the needed dev files are available. Qt Docs indicate I should find a mysql.pro file in src/plugins/sqldrivers/mysql, but I found one only in the QtSDK/QtSources/4.7.1 directory, not QtSDK/QtSources/4.7.2. Simply copying it into 4.7.2 and trying to build there didn't work, too many other files were missing. So I built the 4.7.1 version, and when I rebuilt and ran my program using the installer's version of Qt, I still got QMYSQL driver not loaded. So I can survive for now but the installer was supposed to make life easier I thought... I'd still like to know what's wrong there.
Re: Yet *another* MYSQL drivers not loaded issue
You missed out a very important piece of information in your earlier posts - that you're building Qt in static mode. You can't use regular plugins with statically built Qt. You need the static flavour of plugins that your application needs to be explicitly linked against.
Re: Yet *another* MYSQL drivers not loaded issue
Using the Qt installer, the option is never presented as to whether to build dynamically or statically, but judging by the size of the executable it's clearly a dynamic build. So how do I build the drivers for it?
Re: Yet *another* MYSQL drivers not loaded issue
Quote:
Originally Posted by
MattPhillips
So how do I build the drivers for it?
As far as I remember it comes with MySQL plugin already built. If not, follow the procedure described in the docs.
Re: Yet *another* MYSQL drivers not loaded issue
Well, this is a little late for a followup but as the Qt Updater recently broke my installation of Qt (see previous post of mine) I decided to download and install 4.7.3 (online installer), and now I'm faced with this 'QMYSQL drivers not loaded' nightmare all over again.
Quote:
If not, follow the procedure described in the docs.
Ha! If only. I went to the doc page and neither set of commands given there worked. Specifically,
Quote:
cd $QTDIR/src/plugins/sqldrivers/mysql
qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
make
gave me
Quote:
In file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:52:19: error: mysql.h: No such file or directory
and
Quote:
cd $QTDIR/src/plugins/sqldrivers/mysql
make install
gave me
Quote:
*** No rule to make target `install'. Stop.
I note that $QTDIR isn't defined on my system (so I had to type in the full path, namely QtSDK/QtSources/4.7.3) but I don't see how that should mean anything, I just mention it for completeness.
Has anybody who installed Qt from the online (or offline) installer successfully managed to access the QMYSQL database (or any database besides QSqlLite)? Or do I have to cross my fingers and build Qt from the .tar file again?
Re: Yet *another* MYSQL drivers not loaded issue
You have MySql installed, right?
Re: Yet *another* MYSQL drivers not loaded issue
Yes, up until the reinstall I had been using Qt and MySQL together, successfully, as described in post #9. Connecting to databases, running queries, etc. I also am able to access MySQL databases through independent tools (MySQL Administrator and MySQL Query Browser). I can rebuild from the .tar file as in #9 but that takes hours and it seems ridiculous to have to go through that just to get the MySQL drivers.
Re: Yet *another* MYSQL drivers not loaded issue
Is mysql.h present in /usr/local/include?
Re: Yet *another* MYSQL drivers not loaded issue
No I didn't, I had it in /usr/include/mysql. When I put it in /usr/local/include and re-ran the qmake/make commands, I got
Quote:
g++ -c -pipe -O2 -fvisibility=hidden -fvisibility-inlines-hidden -D_REENTRANT -Wall -W -fPIC -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtSql -I/usr/include/qt4 -I/usr/local/include -I. -o main.o main.cpp
In file included from ../../../sql/drivers/mysql/qsql_mysql.h:52,
from main.cpp:44:
/usr/local/include/mysql.h:70:27: error: mysql_version.h: No such file or directory
/usr/local/include/mysql.h:71:23: error: mysql_com.h: No such file or directory
/usr/local/include/mysql.h:72:24: error: mysql_time.h: No such file or directory
/usr/local/include/mysql.h:74:70: error: my_list.h: No such file or directory
/usr/local/include/mysql.h:132:21: error: typelib.h: No such file or directory
/usr/local/include/mysql.h:147:22: error: my_alloc.h: No such file or directory
In file included from ../../../sql/drivers/mysql/qsql_mysql.h:52,
from main.cpp:44:
/usr/local/include/mysql.h:115: error: use of enum ‘enum_field_types’ without previous declaration
/usr/local/include/mysql.h:153: error: ‘MEM_ROOT’ does not name a type
/usr/local/include/mysql.h:260: error: ‘NET’ does not name a type
/usr/local/include/mysql.h:266: error: ‘MEM_ROOT’ does not name a type
/usr/local/include/mysql.h:285: error: ‘SCRAMBLE_LENGTH’ was not declared in this scope
/usr/local/include/mysql.h:302: error: expected ‘;’ before ‘*’ token
/usr/local/include/mysql.h:326: error: ‘MEM_ROOT’ does not name a type
/usr/local/include/mysql.h:350: error: ‘NET’ does not name a type
/usr/local/include/mysql.h:518: error: use of enum ‘mysql_enum_shutdown_level’ without previous declaration
/usr/local/include/mysql.h:525: error: use of enum ‘enum_mysql_set_option’ without previous declaration
/usr/local/include/mysql.h:672: error: ‘NET’ has not been declared
/usr/local/include/mysql.h:683: error: use of enum ‘enum_field_types’ without previous declaration
/usr/local/include/mysql.h:695: error: ‘MEM_ROOT’ does not name a type
/usr/local/include/mysql.h:696: error: ‘LIST’ does not name a type
/usr/local/include/mysql.h:724: error: ‘MYSQL_ERRMSG_SIZE’ was not declared in this scope
/usr/local/include/mysql.h:725: error: ‘SQLSTATE_LENGTH’ was not declared in this scope
/usr/local/include/mysql.h:767: error: use of enum ‘enum_server_command’ without previous declaration
make: *** [main.o] Error 1
Re: Yet *another* MYSQL drivers not loaded issue
How about passing /usr/local/include/mysql instead of /usr/local/include into configure? The problems you are having are strictly related to files and compilers and not to Qt and MySql.
Re: Yet *another* MYSQL drivers not loaded issue
Thanks wysota, your suggestion was right on track, I should have worked a little harder to get those paths right first. Though the original location of mysql.h was /usr/local/mysql, I don't have a /usr/local/include/mysql folder, so that's what I passed to configure. And I was able to run 'make' unproblematically. However the drivers still don't work. When I cd and run make install I get this:
Quote:
install -m 755 -p "libqsqlmysql.so" "/usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so"
strip --strip-unneeded "/usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so"
This is printed and the console returns to the prompt immediately. I have this in my .pro file, which I've double-checked is correct:
Code:
INCLUDEPATH += /usr/include/mysql
LIBS += -L/usr/lib -lmysqlclient -lmysqlclient_r
But when I try run my program--which worked fine under my previous Qt install--I get the same 'driver not loaded' error as before.
Edit: In the directory $QTDIR/src/plugins/sqldrivers/mysql I now have (due to the make) libqsqlmysql.so. I put in a link to libmysqlclient.so, still didn't work.
Added after 9 minutes:
Got it! I went in and put a link to libqsqlmysql.so in QtSDK/Desktop/Qt/473/gcc/plugins/sqldrivers, and it worked. Is it specified *anywhere* in the documentation that you need to do this? Seriously Qt...
Re: Yet *another* MYSQL drivers not loaded issue
Lol... You didn't tell configure where to put your Qt installation so it put the driver in the default location. Please don't blame Qt, you're the only one to blame here, honestly.