Qt, Mysql driver not loaded (windows)



  • Hello all!
    What i have:
    Qt 5.5
    Mysql 5.7
    What i want?
    connect to mysql by Qt.
    What's hapening?
    error: driver not loaded.
    I copy libmysql.dll in project folder and Qt folder - nothing.
    Next, i trying create plugin with this page http://doc.qt.io/qt-5/sql-driver.html#qmysql
    code:

    qmake "INCLUDEPATH+=C:/Program Files/MySQL/MySQL Server 5.7/include" "LIBS+=C:/Program Files/MySQL/MySQL Server 5.7/lib/libmysql.lib" mysql.pro
       C:\Qt\5.5\Src\qtbase\src\plugins\sqldrivers\mysql>mingw32-make 
    

    give error:

    g++: error: C:/Program: No such file or directory 
    g++: error: Files/MySQL/MySQL: No such file or directory
    

    i create link and repeat

     C:\Qt\5.5\Src\qtbase\src\plugins\sqldrivers\mysql>mklink /j "c:\ow"    
     "C:/Program Files/MySQL/MySQL Server 5.7" *create link* c:\ow «===» C:/Program Files/MySQL/MySQL Server 5.7
    

    aaaand

    C:\Qt\5.5\Src\qtbase\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH+=C:/ow/include" "LIBS+=C:/ow/lib/libmysql.lib" mysql.pro        
    C:\Qt\5.5\Src\qtbase\src\plugins\sqldrivers\mysql>mingw32-make 
    mingw32-make -f Makefile.Release all 
    mingw32-make[1]: Entering directory      'C:/Qt/5.5/Src/qtbase/src/plugins/sqldrivers/mysql' 
    g++ -Wl,-s -shared -Wl,-subsystem,windows -Wl,--out-    implib,C:\Qt\5.5\Src\qtbase\plugins\sqldrivers\libqsqlmysql.a -o     ..\..\..\..\plugins\sqldrivers\qsqlmysql.dll .obj/release/main.o     .obj/release/qsql_mysql.o .obj/release/moc_qsql_mysql_p.o C:/ow/lib/libmysql.lib     -Ls:/lib -LC:/Qt/5.5/mingw492_32/lib -lQt5Sql -lQt5Core     .obj\release\qsqlmysql_resource_res.o 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x120): undefined reference     to `mysql_num_rows@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x14b): undefined reference to `mysql_stmt_num_rows@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x1ea): undefined reference to `mysql_num_rows@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x217): undefined reference to `mysql_stmt_num_rows@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x25e): undefined reference to `mysql_stmt_insert_id@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x29a): undefined reference to `mysql_insert_id@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x618): undefined reference to `mysql_character_set_name@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x889): undefined reference to `mysql_errno@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x8a0): undefined reference to `mysql_field_seek@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x8cc): undefined reference to `mysql_field_seek@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x8d7): undefined reference to `mysql_fetch_field@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x91f): undefined reference to `mysql_fetch_field@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x951): undefined reference to `mysql_error@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x960): undefined reference to `mysql_errno@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0xada): undefined reference to `mysql_errno@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0xb41): undefined reference to `mysql_stmt_error@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0xb4e): undefined reference to `mysql_stmt_errno@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0xd00): undefined reference to `mysql_stmt_data_seek@12' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0xd11): undefined reference to `mysql_stmt_fetch@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0xd7e): undefined reference to `mysql_data_seek@12' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0xd8f): undefined reference to `mysql_fetch_row@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0xeb0): undefined reference to `mysql_fetch_row@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0xef7): undefined reference to `mysql_stmt_fetch@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x1137): undefined 22:21:16  reference to `mysql_fetch_lengths@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x2278): undefined reference to `mysql_init@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x2429): undefined reference to `mysql_real_connect@32' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x25fb): undefined reference to `mysql_set_character_set@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x2612): undefined reference to `mysql_get_client_version@0' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x2630): undefined reference to `mysql_thread_init@0' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x27a2): undefined reference to `mysql_real_connect@32' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x288b): undefined reference to `mysql_close@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x299e): undefined reference to `mysql_options@12' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x29cc): undefined reference to `mysql_options@12' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x29f4): undefined reference to `mysql_options@12' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x2b9e): undefined reference to `mysql_select_db@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x2ccf): undefined reference to `mysql_close@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x2ce6): undefined reference to `mysql_get_server_version@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x2d0e): undefined reference to `mysql_options@12' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x2ec4): undefined reference to `mysql_thread_end@0' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x2ecf): undefined reference to `mysql_close@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x34c9): undefined reference to `mysql_list_fields@12' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x3526): undefined reference to `mysql_fetch_field@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x3535): undefined reference to `mysql_free_result@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x35fa): undefined reference to `mysql_query@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x373a): undefined reference to `mysql_query@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x387a): undefined reference to `mysql_query@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x3af6): undefined reference to `mysql_get_server_version@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x3f83): undefined reference to `mysql_list_tables@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x3fcb): undefined reference to `mysql_data_seek@12' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x3fd6): undefined reference to `mysql_fetch_row@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x41d6): undefined reference to `mysql_free_result@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x45ab): undefined reference to `mysql_num_fields@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x46a4): undefined reference to `mysql_fetch_field@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x4794): undefined reference to `mysql_stmt_result_metadata@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x47c7): undefined reference to `mysql_free_result@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x47e8): undefined reference to `mysql_next_result@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x4805): undefined reference to `mysql_stmt_close@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x482b): undefined reference to `mysql_free_result@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x48e4): undefined reference to `mysql_store_result@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x4c4f): undefined reference to `mysql_real_query@12' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x4d40): undefined reference to `mysql_store_result@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x4d65): undefined reference to `mysql_field_count@4'
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x4da7): undefined reference to `mysql_affected_rows@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x4e5c): undefined reference to `mysql_fetch_field_direct@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x4efe): undefined reference to `mysql_field_count@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x50d7): undefined reference to `mysql_next_result@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x50ff): undefined reference to `mysql_store_result@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x5119): undefined reference to `mysql_field_count@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x523b): undefined reference to `mysql_free_result@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x5347): undefined reference to `mysql_affected_rows@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x53db): undefined reference to `mysql_fetch_field_direct@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x55a4): undefined reference to `mysql_stmt_prepare@12' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x55bd): undefined reference to `mysql_stmt_param_count@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x5627): undefined reference to `mysql_stmt_init@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x57ea): undefined reference to `mysql_stmt_param_count@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x58bc): undefined reference to `mysql_stmt_reset@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x5ada): undefined reference to `mysql_stmt_param_count@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x5af3): undefined reference to `mysql_stmt_execute@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x5c57): undefined reference to `mysql_stmt_affected_rows@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x5c87): undefined reference to `mysql_stmt_bind_result@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x5caa): undefined reference to `mysql_stmt_store_result@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x5cd8): undefined reference to `mysql_stmt_bind_result@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x5d1a): undefined reference to `mysql_stmt_param_count@4' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x6075): undefined reference to `mysql_stmt_bind_param@8' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x64db): undefined reference to `mysql_stmt_attr_set@12' 
    .obj/release/qsql_mysql.o:qsql_mysql.cpp:(.text+0x67e9): undefined reference to `mysql_real_escape_string@16' 
    C:/Qt/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe:     .obj/release/qsql_mysql.o: bad reloc address 0x4 in section `.data' collect2.exe: error: ld returned 1 exit status 
    Makefile.Release:81: recipe for target '..\..\..\..\plugins\sqldrivers\qsqlmysql.dll' failed 
    mingw32-make[1]: *** [..\..\..\..\plugins\sqldrivers\qsqlmysql.dll] Error 1
    mingw32-make[1]: Leaving directory     'C:/Qt/5.5/Src/qtbase/src/plugins/sqldrivers/mysql' 
    makefile:38: recipe for target 'release-all' failed 
    mingw32-make: *** [release-all] Error 2 
    

    well, what do with it?
    SOLVED
    ROBLEM WAS IN BIT DLL. I use mingw32 with mysql64. Update mysql (and i found problem with mysql install https://www.youtube.com/watch?v=iAicUhY-o00&feature=youtu.be) and create plugin again - and everything started to work. Problem was in:

    • plugin

    • list itemway to lib and include must be without link and space.

    • list item64-bit mysql.lib

    about "sql" in .pro and path to lib - of course i do it
    well, need create plugin (4 file in C:\Qt5.1.0\5.1.0\sources\qtbase\plugins\sqldrivers
    libqsqlmysql.a
    libqsqlmysqld.a
    qsqlmysql.dll
    qsqlmysqld.dll ) and update in mingw folders sqldriver and lib
    Thank all for advice


  • Lifetime Qt Champion

    Hi,

    What you should do is rather modify the PATH environment variable in Qt Creator Run part of the Project panel and add the path to where the DLLs are located.

    If you still need to rebuild the MySQL plugin, IIRC MinGW requires some additional steps in order to link against he MySQL libs. I don't have the details at hand sorry.



  • @Psy_Duck Don't forget to add QT +=sql at your .pro file. Better use SQLite3 it's much easier to connect with the help of Qt.



  • For me best way for MySQL connection was use QODBC3 connection. You simply install mysql_odbc drivers and everything works fine on win machine.



  • @mandruk1331 i write sql of course. And i need Mysql.



  • @djmassive you mean "addDatabase("QODBC3")"?
    I have ODBC 5.3 install, but when i try: "Data source not found and no driver specified default".
    I install ODBC 3.1 32-bit, take "myodbc3.dll" and again I received an error



  • Are You trying compile to debug or release ?

    Is your connect command look like this ?
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
    db.setDatabaseName("Driver={MySQL ODBC 5.3 Unicode Driver};Server=yourhost.com;Database=database_name;");
    db.setUserName("username");
    db.setPassword("password");
    bool ok = db.open();

    Please take a look of Driver={MySQL ODBC 5.3 Unicode Driver}
    must be exactly same name as Your in odbc tool in windows

    Remember also to include headers:
    #include <QSqlDatabase>
    #include <QSqlError>
    #include <QSqlQuery>
    #include <QtSql>

    If You make release and use windeployqt, please create folder plugins, and relocate platform folder into plugins folder.

    Drivers from: https://dev.mysql.com/downloads/connector/odbc/ ?

    Odbc windows tools:

    http://i68.tinypic.com/3343lte.png
    

    Folder:

    http://i65.tinypic.com/zmigp1.png
    


  • @djmassive thx for example, i will try it, but i found next way
    PROBLEM WAS IN BIT DLL. I use mingw32 with mysql64. Update mysql (and i found problem with mysql install https://www.youtube.com/watch?v=iAicUhY-o00&feature=youtu.be) and create plugin again - and everything started to work. Problem was in:

    1. plugin
    2. way to lib and include must be without link and space.
    3. 64-bit mysql.lib

    about "sql" in .pro and path to lib - of course i do it
    Thank all for advice
    SOLVED


  • Lifetime Qt Champion

    Glad you found out and thanks for sharing your findings.

    Since you have it working now, please mark the thread as solved using the "Topic Tool" button so other forum users may know a solution has been found :)


Log in to reply
 

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