Cannot establish connection to MySQL database
-
You should check QSqlDatabase::lastError()
-
Hello!
I checked your code. The problem could be:
- If you are on
Windows
you must copy thelibmysql.dll
lib to the application directory. - The database server is not started/working.
Check it and it will work. Happy coding!
- If you are on
-
@Cobra91151 Thank you for your answer. I checked message log on MySQL, it says: 2019-06-30 16:15:59 - MySQL server is currently running
Also I did copy libmysql.dll to the application directory but nothing helps :( -
Then please check with e.g. Dependency Walker if your qt mysql plugin really finds all necessary libraries.
And where did you check for lastError? -
@Christian-Ehrlicher I checked for lastError in the MainWindow, its not written above as I tried that later.
About Dependeny Walker, I'm not very familiar with it, is this what I'm supposed to do: -
@Cobra91151 This is what my application directory contains:
-
It is source directory. Application directory is where your
.exe
file is present (Debug/Release
dir)! That's why it can't locate theMySQL
libs. Copylibmysql.dll
intoDebug/Release
dir (it depends on yourQt Creator
configuration) and start the program. It 100% must work :) -
@Hmmm said in Cannot establish connection to MySQL database:
I checked for lastError in the MainWindow, its not written above as I tried that later.
You have to call it after db.open()
And you should check the qt mysql plugin, not the mysql dll ... it's qsqlmysql.dll/qsqlmysqld.dll and the location is for sure not in your source tree... -
@Christian-Ehrlicher Ok, about lastError, I put it after and it says:
QSqlError("2059", "QMYSQL: Unable to connect", "Authentication plugin 'caching_sha2_password' cannot be loaded: The specified module could not be found.\r\n")`
And this is the ouput of qsqlmysql.dll in Dependeny Walker:
Error: At least one required implicit or forwarded dependency was not found. Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module. Error: Modules with different CPU types were found. Error: A circular dependency was detected. Warning: At least one delay-load dependency module was not found. Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
-
@Cobra91151 Ok, my mistake. I did that now but still the same problem
-
@Hmmm said in Cannot establish connection to MySQL database:
Authentication plugin 'caching_sha2_password' cannot be loaded: The specified module could not be found.
So this is a mysql problem, don't see what Qt can do against it. Maybe google can help here.