PDA

View Full Version : Yet *another* MYSQL drivers not loaded issue



MattPhillips
13th April 2011, 04:34
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/34012-Yet-Another-QMYSQL-driver-not-loaded-issue

didn't help me either. How can I get the driver? (I'm currently getting the 'QSqlDatabase: QMYSQL driver not loaded' error.)

wysota
13th April 2011, 08:06
Do you have MySQL client libraries installed?

MattPhillips
13th April 2011, 14:48
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:


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.

wysota
13th April 2011, 15:49
What is the path to MySQL client library?

MattPhillips
14th April 2011, 17:43
Wysota,

I can't find libmyqslclient.so, which a little googling suggested is the relevant library. It's not in /usr or /etc.
$whereis mysql

gives me


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.

wysota
14th April 2011, 21:52
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.

MattPhillips
18th April 2011, 02:56
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


#include <mysql>

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


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


In function 'global constructors keyed to main':
main.cpp: (.text+0x1): undefined reference to 'qt_plugin_instance_qsqlite()'

wysota
18th April 2011, 11:02
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).

MattPhillips
18th April 2011, 17:08
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.

wysota
18th April 2011, 19:02
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.

MattPhillips
19th April 2011, 00:36
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?

wysota
19th April 2011, 01:09
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.

MattPhillips
22nd June 2011, 04:54
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.


If not, follow the procedure described in the docs.

Ha! If only. I went to the doc page (http://doc.qt.nokia.com/latest/sql-driver.html#qmysql) and neither set of commands given there worked. Specifically,


cd $QTDIR/src/plugins/sqldrivers/mysql
qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
make

gave me


In file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:52:19: error: mysql.h: No such file or directory

and


cd $QTDIR/src/plugins/sqldrivers/mysql
make install

gave me


*** 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?

wysota
22nd June 2011, 08:16
You have MySql installed, right?

MattPhillips
22nd June 2011, 15:27
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.

wysota
22nd June 2011, 16:07
Is mysql.h present in /usr/local/include?

MattPhillips
22nd June 2011, 17:01
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


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

wysota
22nd June 2011, 18:42
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.

MattPhillips
23rd June 2011, 04:05
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:


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:


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...

wysota
23rd June 2011, 09:25
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.

MattPhillips
24th June 2011, 03:26
Please don't blame Qt, you're the only one to blame here, honestly.

I'm not seeing it. Sure, initially I didn't modify the path before I ran make/make install as per the Qt docs, but even after I did that, it still didn't work, and my Qt installation just followed the online installer defaults, aside from installing to QtSDK-4.7.3 as opposed to QtSDK in my home directory. But qmake should know about that. What piece of information was missing that prevented Qt from just putting the library where it was ultimately supposed to know, in the first place?

wysota
24th June 2011, 07:44
What should qmake know about? The source code for Qt has nothing to do with your existing installation. It is not patched to "see" where you install Qt or anything. It is your responsibility to pass a proper path to configure, which you didn't. Simple as that. You wanted to go the short route and while doing that you probably skipped reading how configure works and stuff like that. That's a downside of following tutorials -- sometimes it is better to invest more time to learn and understand some things to waste less time later dealing with problems that arise because of lack of this investment. Of course it is nothing personal, don't be offended. It's just a general rule of thumb. I'll repeat it one more time --- Qt and QtSDK are two different things. Qt source code doesn't even know something like "Qt SDK" even exists so don't expect it to guess that if you're compiling something, you mean to use it with a particular install of Qt SDK.