Unsolved Issues with QMYSQL driver
-
I want to connect qt with mysql databse; i watched this video https://www.youtube.com/watch?v=0quVy31AOw4 and followed the steps. Here's my code.
I included qtsql/qsqldatabase and qdebug in the header file.
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("127.0.0.1");
db.setDatabaseName("slmp");
db.setUserName("root");
db.setPassword("");if (db.open()) ui->db_label->setText("Connected..."); else { ui->db_label->setText("Failed to connect"); }
When i execute this code i of course get the failed to connect text and this statement appears in the output:
19:02:01: Starting D:\workspace\Qt\build-LMS-Desktop_Qt_5_12_3_MSVC2017_32bit-Debug\debug\LMS.exe ...
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7The video states to copy libmysql.dll from the mysql connector c file into the mingw but i still got the same output. Then i noticed the output is building from the mscv2017_32 file so i copied the libmysql.dll there and after running the program and failing to connect i got this output:
19:07:16: Starting D:\workspace\Qt\build-LMS-Desktop_Qt_5_12_3_MSVC2017_32bit-Debug\debug\LMS.exe ...
19:07:21: D:/workspace/Qt/build-LMS-Desktop_Qt_5_12_3_MSVC2017_32bit-Debug/debug/LMS.exe exited with code 0
I'm not sure if the driver is loaded correctly but there's something wrong with my code or if it's something else. I spent the last 2 days searching for a solution with no avail.
-
A good way to check if your Mysql Driver is working, is trying to run the Sql Browser Example on Qt Project.
It will notify you if something is wrong or will add the connection on List of connections
-
I tried running the browser and got a message stating:
An error occurred while opening the connection: Authentication plugin 'caching_sha2_password' cannot be loaded: The specified module could not be found. QMYSQL: Unable to connect
-
@Mocha-Shakea-Khan
Just a thought: I note your own code is being built for 32-bit. Wherever you got thelibmysql.dll
etc. libraries from, did you ensure they too are 32-bit? If they are 64-bit it won't load....P.S.
You don't say whether you are downloading a pre-built QMYSQL or compiling it yourself. If it's the latter, have a read of the stickied thread on this forum, https://forum.qt.io/topic/40672/how-to-create-the-plugin-of-mysql-for-qt. In either case Goggle forQMYSQL driver not loaded
: there are a lot of hits for this (both on this forum & elsewhere) which may sort you out.