MySQL Connection failed,but i entered correct info of server
-
Hello again,
i cant connect my sql server i dont know why.Theres no error,it just when i did
if (db.open())
it will go toelse
which is not able to connect mysql server
this is my codeQSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("localhost"); db.setDatabaseName("pos"); db.setUserName("root"); db.setPort(3306); db.setPassword(""); if (db.open()) {
all info i entered is correct
but i dont know why it doesnt work at all.Please help,
and yea,i downloadedlibmysql.dll
andlibmysqld.dll
and place it toC:\Qt\6.0.1\mingw81_64\bin
Please help mee,thx -
@ELEMENTICY said in MySQL Connection failed,but i entered correct info of server:
Theres no error,
How do you know? I don't see any error handling in your code. Print https://doc.qt.io/qt-5/qsqldatabase.html#lastError in the else block
-
@ELEMENTICY said in MySQL Connection failed,but i entered correct info of server:
and yea,i downloaded libmysql.dll and libmysqld.dll
What compiler were used to build those and what compiler do you use?
-
@ELEMENTICY Did you read my first reply?
-
@jsulm
i do,but qt forum dont let me send another reply within 600 secondi mean theres no error o code,not on database.
But i tried useqDebug() << db.lastError();
and this is the error:
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QPSQL QSqlError("", "Driver not loaded", "Driver not loaded")
-
@ELEMENTICY QMYSQL is not listed as available. I guess you will have to build it by yourself. https://doc.qt.io/qt-5/sql-driver.html
But before that do this: set QT_DEBUG_PLUGINS environment variable to 1 before starting your app and then post its output here. -
@jsulm Hmm,but i saw QMYSQL on
https://doc.qt.io/qt-5/sql-driver.html#qmysql
Maybe because of other reason? -
Hi,
The plugin is currently not pre-built anymore as Oracle changed their licensing with regards to MySQL so you'll have to build it yourself.
-
-
@ELEMENTICY said in MySQL Connection failed,but i entered correct info of server:
Can you teach me or explain it to me please?Thank you
Go to @jsulm's link again and scroll down. There is a section called "How to Build the QMYSQL Plugin on Windows" -- it contains instructions on how to build the DLL.
-
@JKSH yea,i just found it after i said that.
Can you help vote any of my question? So i have repulation or else i have to wait 600 second everytimehttps://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows
here is it
-
@ELEMENTICY said in MySQL Connection failed,but i entered correct info of server:
I tried it,it doesnt work.
Can you help again xDYou need to provide details of what you tried and what errors you got. Without the details, we can't help you.