The installation on another computer does not recognize the MySQL connection, but on my computer where I created the project it recognizes it fine.
-
Hello, my problem is that when I create the setup, but when I install it on a second Windows 64 computer, it does not recognize the MySQL connection.
On my computer where I created the project, it works fine and recognizes the MySQL connection.
What I did:
1- Build the project in Realese.
2- I transferred the necessary data to the Realese folder using Windows EmbedLoyqt.exe.
3- I manually placed the libmysql.dll file in the same folder as the executable.
4- I authorized remote access on my server from my computer and from a second computer;
5- When I installed it on the second computer, I checked all the files and folders, and they were all transferred without problems, that is, the same ones that are in the Realese folder are also installed on the second computer.
I tested it on my computer and everything works fine, but on a second computer it does not recognize the connection.
The installation on the second computer was successful, but when I run the username and password, it does not recognize the connection.
Another piece of information is that when I manually remove the libmysql.dll file from the executable folder, the same error occurs on my computer as on the second computer, but in this case I do not remove the libmysql file from the second computer.
Could you please help me? -
Hi.
Is the MySql database located on the first computer ? or on a third one ? Is the database reachable by the second computer ?
What error message do you get exactly ? what do you mean when you say the connection is not "recognized" ? -
Hi.
I have a local connection using XAMPP and the connection to the MySQL database works fine for the moment I'm developing, but that's not the one I'm talking about.The database I'm talking about is on my Hostgator server, where I put my projects to be online.
And there I also have the MySQL database, that's the one I'm talking about, in fact I've already authorized my computer and the second computer for a remote connection, as I mentioned before. But only the computer where I developed the project can connect. When I install it on the second computer, it doesn't recognize the connection to the database.
-
I created and installed the setup on both computers.
I created a login system, and I can log in with my computer, which I use to develop the project, that is, it recognizes the username and password, but when I log in with the second computer, it gives me an error message that it does not recognize the connection to the database. -
@Jeferson said in The installation on another computer does not recognize the MySQL connection, but on my computer where I created the project it recognizes it fine.:
I created and installed the setup on both computers.
I created a login system, and I can log in with my computer, which I use to develop the project, that is, it recognizes the username and password, but when I log in with the second computer, it gives me an error message that it does not recognize the connection to the database.What do you mean by "recognize the connection" ? What is the error message ?
Is this unknown host ? wrong credentials ? unreachable address ? port closed ? Anything else ? -
DbManager& DbManager::getInstance() {
static DbManager instance;
return instance;
}DbManager::DbManager() {
db = QSqlDatabase::addDatabase("QMYSQL");db.setHostName("localhost"); db.setDatabaseName("DbName"); db.setUserName("root"); db.setPassword(""); db.setConnectOptions("CLIENT_SSL=1");
}
bool DbManager::connect() {
if (!db.open()) {qDebug() << "Available Drivers:" << QSqlDatabase::drivers(); QMessageBox::critical(nullptr, "Erro", "Error connecting to database: " + db.lastError().text()); return false; } return true;
}
QSqlDatabase DbManager::getDatabase() {
return db;
}bool DbManager::supportsTransactions() const {
QSqlDatabase db = QSqlDatabase::database();
if (!db.driver()->hasFeature(QSqlDriver::Transactions)) {
QMessageBox::critical(nullptr, "Erro", "Erro");
return false;
}
return true;
} -
And who should be able to read this and what error do you get?
Please format your code with the code tags (</>
).
Also make sure to deploy all dependencies as described here: https://doc.qt.io/qt-6/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows"When you distribute your application, remember to include libmysql.dll / libmariadb.dll in your installation package. It must be placed in the same folder as the application executable. libmysql.dll additionally needs the MSVC runtime libraries which can be installed with vcredist.exe"
-
@Jeferson said in The installation on another computer does not recognize the MySQL connection, but on my computer where I created the project it recognizes it fine.:
db.setHostName("localhost");
Yep ... There is the problem ...
The problem is that when you try to connect to localhost, you try to establish connection with a service that is located on the very same machine. This is the reason why your app connects to the DB on the first machine and not on the second one.
Because your app on the second computer tries to access to the database on the second computer itself, while your DB runs on the first computer. So for sure there's no risk for the connection to succeed.If you want your second computer to access the DB on the first machine, you have to call the address of the first computer, not localhost.
-
Like @ankou29666 said.
I have a separate question though: you really have a free floating mysql on the internet with root access enabled?