PDA

View Full Version : Trouble installing mysql driver



premroxx
23rd June 2012, 05:36
I have tried numerous ways, based on the posts i've read on this forum, but I still have problems with installing it.

I have tried
configure -plugin-sql-mysql

C:\Qt\2009.01\qt> cd src\plugins\sqldrivers\mysql
C:\Qt\2009.01\qt\src\plugins\sqldrivers\mysql> set MYSQL_PATH=c:mysql
C:\Qt\2009.01\qt\src\plugins\sqldrivers\mysql> reimp -d %MYSQL_PATH%\lib\opt\libmysql.lib
C:\Qt\2009.01\qt\src\plugins\sqldrivers\mysql> dlltool -k --input-def LIBMYSQL.def --dllname libmysql.dll --output-lib libmysql.a
C:\Qt\2009.01\qt\src\plugins\sqldrivers\mysql> qmake "INCLUDEPATH+=%MYSQL_PATH%include" "LIBS+=-L. -lmysql" mysql.pro
nmake

It ran fine & generated qsqlmysql4.lib, qsqlmysql4.dll files. I've also put them in the library path & in the qt bin folder(just to be sure.) But the msql is still isnt getting picked up

#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlError>
#include <QtSql/QSqlQuery>
#include <QtSql/QMYSQLDriver>
#include <QtSql/qsql_mysql.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
QString s( QSqlDatabase::drivers().join( "." )) ;
qDebug()<< s;
}

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE
"QSQLITE"

What am i doing wrong here

ChrisW67
23rd June 2012, 06:21
What am i doing wrong here

If had a dollar/pound/złoty for every time someone followed an incomplete or incorrect "tutorial" thinking they were saving themselves time... A whole bunch of the stuff you have done was completely unnecessary, e.g. the reimp and dlltool stuff is for MinGW when you clearly are using Microsoft's tools. However, you missed the obvious and necessary:


nmake install

after building the plugin.

premroxx
23rd June 2012, 06:38
Oh. Would i just have to run the following two commands?

configure -plugin-sql-mysql
nmake install

premroxx
23rd June 2012, 17:56
Its still not working. the nmake install ran without any problems, but the mysql plugin is isnt getting picked up.

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE
"QSQLITE"

ChrisW67
23rd June 2012, 23:57
It is all in the documentation. You have two different ways to do it:

Building the Drivers Using Configure. You build and install the MySQL plugin as you build and install the Qt library itself, OR
How to Build the QMYSQL Plugin on Windows. You build and install the plugin on its own after you have built and installed Qt.

Pick one.

For option 1: You use the Qt configure script to tell Qt to build the plugin, then build Qt, install Qt, done. Here is an example. It is not exactly what you type. You have to adapt it to your system


cd {qt source dir}
configure {... other options ...} -Ic:/mysql/include -Lc:/mysql/lib -lmysql -plugin-sql-mysql
nmake
nmake install


For option 2: You move to the plugin source directory, run qmake with some options, make, install, done. Here is an example. It is not exactly what you type. You have to adapt it to your system


cd %QTDIR%\src\plugins\sqldrivers\mysql
qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib" mysql.pro
nmake
nmake install

You might recognise that as being exactly what is in the manual with the install step added.

If you already have Qt and MySql installed the total time for Option 2 is less than ten minutes.