Important: Please read the Qt Code of Conduct -

[SOLVED] problems with QT5.4 x64, mingw w64 an MySql 64bit on Win7

  • I am running a third-party sjlj build from and attempting to connect to Mysql server.
    System environment: Windows 7, 64bit
    -Qt Creator 3.4
    -MySQL 64bit (tried 5.5, 5.6, 5.7) all with same result.
    Initially used included qsqlmysql files from third-party build. While in Debug, it fails with SIGSEGV (Segmentation fault) while attempting to open the connection to the server.

    • QSqlDatabase::db
    • db.Open

    Then I build my own driver, everything builds great. While in debug, it fails again with SIGSEGV (Segmentation fault). But this time it fails inside qsql_mysql.cpp line 1265

    if ((d->mysql = mysql_init((MYSQL*) 0)) &&
                                   host.isNull() ? static_cast<const char *>(0)
                                                 : host.toLocal8Bit().constData(),
                                   user.isNull() ? static_cast<const char *>(0)
                                                 : user.toLocal8Bit().constData(),
                                   password.isNull() ? static_cast<const char *>(0)
                                                     : password.toLocal8Bit().constData(),
                                   db.isNull() ? static_cast<const char *>(0)
                                               : db.toLocal8Bit().constData(),
                                   (port > -1) ? port : 0,
                                   unixSocket.isNull() ? static_cast<const char *>(0)
                                               : unixSocket.toLocal8Bit().constData(),
            if (!db.isEmpty() && mysql_select_db(d->mysql, db.toLocal8Bit().constData())) {
                setLastError(qMakeError(tr("Unable to open database '%1'").arg(db), QSqlError::ConnectionError, d));
                return false;
    #if MYSQL_VERSION_ID >= 50000
                mysql_options(d->mysql, MYSQL_OPT_RECONNECT, &reconnect);
        } else {
            setLastError(qMakeError(tr("Unable to connect"),
                         QSqlError::ConnectionError, d));
            d->mysql = NULL;
            return false;

    I am not receiving the else notice of "Unable to connect"

    I believe my driver is working, but am unsure where to look from here.
    If we build on QT4.5 32bit, wingw32, things work fine. We can even run on a Mysql 64bit install using a libmysql.dll from a 32 bit mysql install. not a desired condition.
    We have been fighting this for a few days now.
    Thank you in advance for any help or direction.

    [edit: Added missing coding tags ```before and after SGaist]

  • @swankster
    Solution was, finding this gem then making a few modifications. Basically rebuilding MySQL Connector.C 6.1\lib\libmysql.dll with gendef.exe
    will need to Install Ruby x64, I used (rubyinstaller-2.2.2-x64.exe)
    set Ruby...\bin to System Variables.
    copy C:\Program Files\MySQL\MySQL Connector.C 6.1 to C: and rename as \mysql-connector
    open cmd window
    > gendef.exe libmysql.dll
    > dlltool -v --dllname libmysql.dll --def libmysql.def --output-lib libmysql.lib
    > gem install mysql2 --no-rdoc --no-ri -- '--with-mysql-lib="C:\mysql-connector\lib" --with-mysql-include="C:\mysql-connector\include"'

    copy c:\mysql-connector\lib\libmysql.lib
    to c:\Program Files\MySQL\MySQL Server 5.6\lib

    copy c:\Ruby22-x64\lib\ruby\gems\2.2.0\gems\mysql2-0.3.18-x64-mingw32\vendor\libmysql.dll
    to c:\Program Files\MySQL\MySQL Server 5.6\lib

    Now build MySql Driver for QT. I used third party QT 64 from
    put in System Variables
    Create QT cmd window (needs custom qtenv.bat file, copied from other QT version and modified for x64)
    from QT cmd x64

    set mysql=C:\PROGRA~1\MySQL\MYSQLS~1.6 (must be short names)
    cd c:\Qt\qt-5.4.1-src\qtbase\src\plugins\sqldrivers\mysql
    qmake "INCLUDEPATH+=%mysql%\include" "LIBS+=%mysql%\lib\libmysql.lib" -o Makefile

    copy qsqlmysql.dll and qsqlmysqld.dll from C:\Qt\qt-5.4.1-src\qtbase\plugins\sqldrivers to c:\Qt\5.4.1-x64\mingw492r1-sjlj-rev1\qt-5.4.1-x64-mingw492r1-sjlj-rev1\plugins\sqldrivers

    copy %mysql%\lib\libmysql.dll c:\windows

    Hope this helps someone else save a few days worth of time and aggravation.