[Windows] mysql compiled, available but not loaded
-
Dear all,
I compiled my mysql dll with msvc following the "manual":http://doc.trolltech.com/4.7/sql-driver.html#qmysql-for-mysql-4-and-higher:Dowloaded the Windows x86, 32bit ZIP Archive from "there
":http://www.mysql.com/downloads/mysql#
Then launched the following command (path are a bit different than the official manual)
@ cd %QTDIR%\src\plugins\sqldrivers\mysql
qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\lib\libmysql.lib" mysql.pro
nmake@I also recompiled QSQLITE, just to compare
I copied C:\Mysql\lib\libmysql.dll next to qsqlmysql4.dll in %QTDIR%\plugins\sqldrivers
Then when I launch my prog and I get:
@Debug: qApp->libraryPaths() = C:/Qt/4.7-x86/plugins - E:/Dev/SQLMsvc/release
Debug: QSqlDatabase::drivers() = QSQLITE
QSqlDatabase:: QMYSQL driver not loaded
QSqlDatabase:: available drivers; QSQLITE@My dll seems to be compiled correctly : I checked the registry and found my plugin in 4.7.false but not in 4.7
!http://pix.wefrag.com/i/b/8/2/9/b/30861ba38bf6fb1520bc5388a58bd3a2.png(4.7)!
!http://pix.wefrag.com/i/9/3/0/3/f/30862f931b965e38d385c6fbb096ee65.png(4.7.false)!So what is wrong with my sql plugin?
-
Ok, I moved libmysql.dll in my application directory and now I get: @Debug: qApp->libraryPaths() = C:/Qt/4.7-x86/plugins - E:/Dev/SQLMsvc/release
Debug: QSqlDatabase::drivers() = QSQLITE - QMYSQL3 - QMYSQL
Driver not loaded@ So, now the plugin is correcly found, but as soon as I create a new QSqlDatabase("QMYSQL") I get this Driver not loaded error. -
I have the same probelm, can somebody help?
-
Can you try setting your PATH environment variable to contain the path to libmysql.dll? It will not help to put libmysql.dll in your application directory or in the plugins directory. In case you don't want to change your environment variable, then you can instead try putting libmysql.dll in yourQtDirectory/bin together with the Qt dlls.
-
Where should I put libmysql.dll when redistributing my app?
-
best would be to the directory of your binary (exe) file, as that is the first dir that windows scans for dlls.
-
Got the same problem, but nothing helps. I had QMYSQL driver listed as available, also I copied libmysql.dll to QtDir/bin and placed all mysql dlls in my library paths, but still receive:
QSqlError(-1, "Driver not loaded", "Driver not loaded")
Any other ideas? Now I'm considering use QODBC.
-
Did you tried copying libmysql.dll next to your program exe?
-
Yep, still nothing. BTW, it's one of my library paths. I tried even with different versions of MySQL Server (the same problems with 5.5 and 5.6).
-
I do not have experience with MySQL but with PostgreSQL. From what I have found there is sometimes more than just the lib*sql.dll that the app needs to load before the plugin works. Get something like dependency walker and check what is needed by libmysql.dll and add all of those to the app dir, or just copy everything in the bin folder of MySQL into the app dir and check if that does not work.
-
Dependency walker has shown nothing additional stuff, so it's not it, but thank you for your hint. Well, I recompiled drivers once again and tried from scratch with most trivial database opening. The code is below.
@
QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("mysql.agh.edu.pl");
db.setUserName("thoron");
db.setPassword("mypassword");
db.setPort(3306);
db.setDatabaseName("thoron");if(db.open()) { qDebug()<<"Database is open."; } else { qDebug()<<db.lastError(); }@
What is interesting, that SQL drivers are loaded properly, but I receive error like this:
QSqlError(2003, "QMYSQL: Unable to connect", "Can't connect to MySQL server on 'mysql.agh.edu.pl' (10060)")
It seems to be sort of an error on the database site. However, I'm still getting it despite firewall being remotely closed. Database is on some mySQL server, not on my machine and I can access it by, for example php script. Do you have any hints on that?
-
Are you sure this sql server allows connection from outside? I know it's not allowed on my webhost.
Try locally first to debug your code. -
It may be sort of this problem. I created mySQL database on my localhost and it can be reached from Qt without any issues. The previous database was off of my student account on my university, so maybe it's not allowed to reach from my machine. Anywa thank you guys for all guidance. I'm getting mad. :)
-
For me the solution was to put libmysql.dll into C:\Windows or in the $PATH variable. In addition I have also put qsqlmysql4.dll into a folder named "sqldrivers".
That folder is placed in the same place that the executable.
-
I tried putting libmysql.dll into C:\Windows (I am using Windows 7). I did not want to deal with the $PATH variable because that's solely in the command line and most of my directories are long filenames.
I put qsqlmysql.dll and qsqlmysqld.dll into a folder called sqldrivers in the %ProjectFolder%/Win32/Debug folder along w/ my executable so it's basically:
%ProjectFolder%
-Win32
--Debug
---sqldrivers
----qsqlmysql.dll
----qsqlmysqld.dllI have tried rebuilding the plugin, no use. Someone suggested it as a problem with the database but I had downloaded yesterday MySQL workbench from MYSQL and used that to create the first table of the application. I also (when I read that), went to eclipse and wrote a small application in Java to do the query I was trying to do to start with (basically the 'get all' atomic read function).
I'm so close to scrapping QT for SQL and just writing my own wrapper using MySQL itself but like the look of the API if it would JUST work!