How to install MySql Driver?

  • It's about 3 days I'm working on install mysql driver but it hasn't worked. first i tested with xampp and didn't work, second i decided install mysql server but it didn't work either, i wrote this instructions in "Start>All Program>Qt SDK>Desktop>Qt 4.8.1 for Desktop (MinGW)"

    @cd C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql
    qmake "INCLUDEPATH+=C:\Program Files\MySQL\MySQL Server 5.6\include" "LIBS+=C:\Program Files\MySQL\MySQL Server 5.6\lib"

    but cmd show me 2 errors for example:

    @ make[1]: ***[tmp/obj/debug_shared/main.o] Error 1
    make[1]: leaving directory '/c/QtSDK/QtSources/4.8.1/src/plugins/sqldrivers/mysql'@

    I have no idea what i must to do. please tell me what must i do

  • Maybe it will be helpful for you
    "Create MySQL driver for Qt5":

  • Thank you for your consideration. when I use single path separator show me this WARNING let me show the code in single separator:

    @C:\WINDOWS\system32>set mysql=C:\Program Files\MySQL\MySQL Server 5.6

    C:\WINDOWS\system32>cd C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql

    C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH+=C:\Pro
    gram Files\MySQL\MySQL Server 5.6\include" "LIBS+=C:\Program Files\MySQL\MySQL S
    erver 5.6\lib\libmysql.lib"
    WARNING: (internal):1: Unescaped backslashes are deprecated.
    WARNING: (internal):1: Unescaped backslashes are deprecated.
    WARNING: (internal):1: Unescaped backslashes are deprecated.@

    and my compiler is MinGW also I've read "This link":
    @aklenczar my version is 4.8.1 and test your way but it didn't work and it shows the same error.
    by the way, i must say my OS is XP

  • Lifetime Qt Champion


    Two things i can think of:

    1. you are missing a -L before your MySQL path in your LIBS statement
    2. Using spaces in lib path on windows has always been a problem (quoted or not, at least for me) I've always reverted to either having all paths without spaces or use the 8.3 names of the folders

    Hope it helps

  • Hi SGaist.
    my 'libmysql.ilb' file is in this directory:
    C:\Program Files\MySQL\MySQL Server 5.6\lib\libmysql.lib
    and my 'include' folder in this:
    C:\Program Files\MySQL\MySQL Server 5.6\include
    I changed MySql path to this:

    @C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH+=C:\PROGRA~1\MySQL\MYSQLS~1.6\include" "LIBS+=C:\PROGRA~1\MySQL\MYSQLS~1.6\LIB\LIBMYS~1.lib"
    although this code show me the same Error, may be I wrote wrong 8.3 name.
    it's better to see if my path is correct or not

  • Lifetime Qt Champion

    Just to be sure, what compiler are you using ?

  • OK. my compiler is MinGW

  • Lifetime Qt Champion

  • my compiler is installed with qt creator in default setting, do you think is necessary download MinGW in order to this instructions?

  • Lifetime Qt Champion

    No need to download another MinGW, use the one that came with Qt

  • I skip this part:
    (Open the DOS prompt, go to C:\MySQL\MySQL51\lib\opt, and run the following commands:
    reimp -d libmysql.lib
    dlltool -k -d libmysql.def -l libmysql.a)
    Because, it shows this message:

    @C:\PROGRA~1\MySQL\MYSQLS~1.6\lib>reimp -d libmysql.lib
    'reimp' is not recognized as an internal or external command,
    operable program or batch file.@

    also I don't have 'opt' folder, I just have 'C:\Program Files\MySQL\MySQL Server 5.6\lib\libmysql.lib'
    Then, I wrote this part:
    @C:\QtSDK\QTSOUR~1\4.8.1>configure.exe -debug-and-release -platform win32-g++ -qt
    -sql-mysql -l mysql -I C:\PROGRA~1\MySQL\MYSQLS~1.6\include -L C:\PROGRA~1\
    and after long time this error appeared:
    @mingw32-make[2]: *** [../../lib/QtSqld4.dll] Error 1
    mingw32-make[2]: Leaving directory c:/QtSDK/QTSOUR~1/4.8.1/src/sql' mingw32-make[1]: *** [debug-all] Error 2 mingw32-make[1]: Leaving directoryc:/QtSDK/QTSOUR~1/4.8.1/src/sql'
    mingw32-make: *** [sub-sql-sub_src_target_ordered] Error 2@

    I think these error are for my version of Qt4.8.1 and mySql5.6 because these instructions are provided for MySql5.1 and Qt4.6.2, am I right?

  • Lifetime Qt Champion

    You need to install reimp for MinGW, the paths might have changed in between but the basics stay the same

  • oh you're right. But if I run
    @reimp -d libmysql.lib@

    will libmysql.def and libmysql.a be created?
    Because I don't have them now in order to rest of the process.

  • Lifetime Qt Champion

    reimp to create libmysql.def
    dlltool to create libmysql.a

  • so you haven't followed the instructions carefully. all the steps mentioned by SGaist was completely described.

  • this is the first time i hear about rimp

  • I've done both of your ways, I succeeded to make libmysql.def and libmysql.a, Then I ran this code
    @C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql>configure.exe -debug-and-release -platform win32-g++ -qt-sql-mysql -l mysql -I C:\Program Files\MySQL\MySQL Server 5.6\include -L C:\Program Files\MySQL\MySQL Server 5.6\lib@
    (I used path with space because of -I and -L) after a while it shows many messages some of them is:

    @c:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug all
    mingw32-make[3]: Entering directory c:/QtSDK/QtSources/4.8.1/src/imports/shaders'
    mingw32-make[3]: Nothing to be done for all'. mingw32-make[3]: Leaving directoryc:/QtSDK/QtSources/4.8.1/src/imports/shaders'
    c:/QtSDK/mingw/bin/mingw32-make -f Makefile.Release all
    mingw32-make[3]: Entering directory c:/QtSDK/QtSources/4.8.1/src/imports/shaders' mingw32-make[3]: Nothing to be done forall'.
    mingw32-make[3]: Leaving directory c:/QtSDK/QtSources/4.8.1/src/imports/shaders' mingw32-make[2]: Leaving directoryc:/QtSDK/QtSources/4.8.1/src/imports/shaders'
    mingw32-make[1]: Leaving directory `c:/QtSDK/QtSources/4.8.1/src/imports'@
    i ignored them and ran next step
    @C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH+=C:\PR
    OGRA~1\MySQL\MYSQLS~1.6\include" "LIBS+=-L. mysql"

    and i saw no error, but mysql driver wasn't installed.
    i decided use Mohsen's method, with ran this method i have libqsqlmysql4.a
    In "C:\QtSDK\QtSources\4.8.1\plugins\sqldrivers" i copied them to my project but when i run this code
    @qDebug() << QSqlDatabase::drivers();@
    i don't see qmysql driver

    • if you're running your application through QtCreator you won't need to copy them into your app dir. it's just enough having them in "C:\QtSDK\QtSources\4.8.1\plugins\sqldrivers" just making sure your other Qt libs are in "C:\QtSDK\QtSources\4.8.1\lib" and this is the path where you've defined in QTDIR. otherwise if this is only the path of sources directory then you must move the result binaries onto the main Qt directory path/plugins/sqldrivers.

    • if you're trying to make a release then you'll need to have qmysql.dll and libmysql.dll in "[YOUR EXE PATH]/sqldrivers/"

  • Ok, but there are many files in my “C:\QtSDK\QtSources\4.8.1\lib”, and in my path/plugins/sqldrivers these files exist:(libqsqlite4.a, libqsqlited4.a, libqsqlmysql4.a, libqsqlmysqld4.a, qsqlite4.dll, qsqlited4.dll, libqsqlmysql4.a, qsqlmysqld4.dll) and empty 'mysql' folder.
    are those enough?
    I need to say i just serch 'QMYSQLDriver' then i find it in few directories:
    can I use them? how do I use them?

  • however Qt keeps binary compatibility but it's better to use plugins built with same version. I can't further help you making that plugin available in your project since i don't know how Qt's configured and defined on your system.
    i just can point you to review the path of Qt version in use both on Environment Variables/QTDIR and QtCreator/options/build&run/Qt Versions once again.

  • ok thanks all of you.

  • Hey guys, i'm having a similar problem and my context is very similar.

    I'm trying to compile the mysql driver using qt5 and mysqlserver 5.6, using mingw too and tryed to follow the tutorial "here": I did the reimp sucessfully creating the libmysql.a, i used the configure command sucessfully, but got an error trying to compile using mingw32-make sub-src. The errors are undefined references when trying to compile the mysql module.

    configure.exe -debug-and-release -platform win32-g++ -qt-sql-mysql -l mysql -I "C:\PROGRA~1\MySQL\MYSQLS~1.6\include" -L "C:\PROGRA~1\MySQL\MYSQLS~1.6\LIB"

    mingw32-make sub-src
    @mingw32-make[3]: Entering directory 'C:/Users/Hugo/Downloads/qt-everywhere-opensource-src-5.0.1/qtbase/src/sql'
    g++ -shared -Wl,--out-implib,C:\Users\Hugo\Downloads\qt-everywhere-opensource-src-5.0.1\qtbase\lib\libQt5Sqld.a -o ....\lib\Qt5Sqld.dll object_script.Qt5Sqld.Debug -lmysql -LC:/PROGRA~1/MySQL/MYSQLS
    ~1.6/LIB -LC:/Users/Hugo/Downloads/qt-everywhere-opensource-src-5.0.1/qtbase/lib -lQt5Cored .obj\debug_shared\Qt5Sqld_resource_res.o
    ./.obj\debug_shared\qsql_mysql.o: In function codec': C:\Users\Hugo\Downloads\qt-everywhere-opensource-src-5.0.1\qtbase\src\sql/drivers/mysql/qsql_mysql.cpp:223: undefined reference tomysql_character_set_name@4'
    ./.obj\debug_shared\qsql_mysql.o: In function qMakeError': C:\Users\Hugo\Downloads\qt-everywhere-opensource-src-5.0.1\qtbase\src\sql/drivers/mysql/qsql_mysql.cpp:234: undefined reference tomysql_error@4'
    C:\Users\Hugo\Downloads\qt-everywhere-opensource-src-5.0.1\qtbase\src\sql/drivers/mysql/qsql_mysql.cpp:237: undefined reference to mysql_errno@4' ./.obj\debug_shared\qsql_mysql.o: In functionqMakeStmtError':
    C:\Users\Hugo\Downloads\qt-everywhere-opensource-src-5.0.1\qtbase\src\sql/drivers/mysql/qsql_mysql.cpp:309: undefined reference to mysql_stmt_error@4' C:\Users\Hugo\Downloads\qt-everywhere-opensource-src-5.0.1\qtbase\src\sql/drivers/mysql/qsql_mysql.cpp:312: undefined reference tomysql_stmt_errno@4'
    ./.obj\debug_shared\qsql_mysql.o: In function ZN19QMYSQLResultPrivate12bindInValuesEv': C:\Users\Hugo\Downloads\qt-everywhere-opensource-src-5.0.1\qtbase\src\sql/drivers/mysql/qsql_mysql.cpp:358: undefined reference tomysql_stmt_result_metadata@4'

  • Anyone?

    I guess my problem is with the reimp not generating a usable libmysql.a, when i use the reimp in the mingw-utils0.3 i got the output just fine, but all the procedures as i described before fail. When downloading the last version of mingw-utils(0.4) i try to use de reimp but it says libmysql.lib is corrupted or something... so i guess this is where the problem come from.

    Any thoughts? help?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.