Do you have MySQL client libraries installed?
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.
Last edited by MattPhillips; 13th April 2011 at 15:12.
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$whereis mysql
In /usr/lib/mysql/plugin and /usr/lib/mysql/plugin I have ha_innodb_plugin.so.mysql: /usr/bin/mysql /etc/mysql /usr/lib/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
The MySQL administrator says the socket for the server instance (which is running) is /var/run/mysqld/mysqld.sock, if that helps.
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.
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
Still 'mysql driver not loaded'.LIBS += -L/usr/lib -lmysqlclient
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()'
Last edited by MattPhillips; 18th April 2011 at 05:30.
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).
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.
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.
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?
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.
Ha! If only. I went to the doc page and neither set of commands given there worked. Specifically,If not, follow the procedure described in the docs.
gave mecd $QTDIR/src/plugins/sqldrivers/mysql
qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
make
andIn file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:52:19: error: mysql.h: No such file or directory
gave mecd $QTDIR/src/plugins/sqldrivers/mysql
make install
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.*** No rule to make target `install'. Stop.
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?
Bookmarks