QSqlDatabase: QMYSQL driver not loaded on Windows
-
Hello,
I realize this is a problem that has been addressed on here, I've been reading posts and trying things, but I just can't get this to work.
I'm getting the "QMYSQL driver not loaded" error. I'm on Windows 10. I have Qt 6.3.1 (that's what the folder off of the Qt root has) and am using mingw_64.
I used MySql Workbench to create the database and a table and populate it and that all is in place.
Then, I basically followed what this guy is doing in this tutorial:
https://www.youtube.com/watch?v=_u7TcjIDNzw&t=451s&ab_channel=ParwizForoghI added the libmysql.dll and libmysqld.dll into the "bin" folder. That is in: Qt/6.3.1/mingw_64/bin. I also put the dlls where the executable is. The debug executable.
I have these headers:
#include <QtSql> #include <QSqlDatabase>
and I have this code to connect to the database:
void MainWindow::on_btnTransferData_clicked() { QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("127.0.0.1"); db.setUserName("root"); db.setPassword("root"); db.setDatabaseName("accordtest"); if(db.open()){ QMessageBox::information(this,"Connection","Database Connected Successfully!"); }else{ QMessageBox::information(this,"Not Connected","Database is Not Connected."); } }
At the end of all of this, it's still refusing to connect.
Here is the application output in the Qt Creator Application Output window:
20:17:47: Starting E:\Projects\Fiverr\deovindice\build-SimpleApp-Desktop_Qt_6_3_1_MinGW_64_bit-Debug\debug\SimpleApp.exe... QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QPSQL QML debugging is enabled. Only use this in a safe environment. 20:17:55: E:\Projects\Fiverr\deovindice\build-SimpleApp-Desktop_Qt_6_3_1_MinGW_64_bit-Debug\debug\SimpleApp.exe exited with code 0
I'd appreciate any help with this. I am new to Qt. I just started using it a few days ago.
Thanks!
...John -
@jalway said in QSqlDatabase: QMYSQL driver not loaded on Windows:
I added the libmysql.dll and libmysqld.dll into the "bin" folder. That is in: Qt/6.3.1/mingw_64/bin. I also put the dlls where the executable is.
And do you also compile the Qt mysql plugin as decribed in the documentation and asked here at least twice a week?
-
@Christian-Ehrlicher -- Ah, documentation. I had not seen it. That led me in the right direction. So it works now. I didn't realize there was a "plugin" directory and that the plugin had to be up to date. Thanks!
-
Then please mark this topic as solved, thx.