Issues with QMYSQL driver
-
wrote on 21 Apr 2019, 00:12 last edited by Mocha Shakea Khan
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.
-
wrote on 21 Apr 2019, 00:37 last edited by
-
wrote on 21 Apr 2019, 00:52 last edited by
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
-
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
wrote on 22 Apr 2019, 08:21 last edited by JonB@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.
1/4