connecting MySQL remotely
Hello everybody!
I have written a program that needs to connect to a mysql db installed on one of the computers in the network. All others computers in the network running the program should be able to connect to the db.
I have a script that connect to the server, it looks like this:
Code:
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QFile>
#include <QTextStream>
#include <QString>
static bool createConnection()
{
file.setFileName("connection.txt");
qApp->tr("Cannot open connection file."
return false;
}
QString DatabaseName
= in.
readLine();
//db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1");
db.setPort (3306);
db.setDatabaseName( DatabaseName );
db.setUserName( UserName );
db.setPassword( Password );
db.setHostName( HostName );
if (!db.open()) {
QMessageBox::critical(0, qApp
->tr
("Cannot open database"),
qApp->tr("Unable to establish a database connection."
return false;
}
return true;
}
#endif
The program works when running on the computer where MySQL is installed but fails to connect when running on all the computers in the network.
I am using the ip address of the MySQL server as hostname.
Hope that someone could help me out in this.
Thanks in advance!
Re: connecting MySQL remotely
I don't know, whether it is a help. I don't have that much experience with MySQL, but quite some with Postgres. In Postgres you have to activate the remote access in the config files. With the default settings you can only have only local connections. It is a security feature. Perhaps it is the same with MySQL?
Re: connecting MySQL remotely
thanks for the reply. The MySQL server is setup to accept tcp/ip connection during the configuration. I do not see any other way in further configuring this. Am I missing something? By the way the database is running on windows machine and I am using MySQL 5.
Re: connecting MySQL remotely
As I said, I am not that experienced with MySQL. But since you can connect locally your code cannot be that wrong. I still suspect a permissions problem.
A short google search:
http://help.hardhathosting.com/question.php/87
http://www.plus2net.com/articles/con...e_mysql_db.php
Are you sure all your 'GRANTS' are correct?
Re: connecting MySQL remotely
Yes. the user is setup to access the db from any host and has the right privileges.
Re: connecting MySQL remotely
Ok, then I give up. Only one thing, can you connect without your Qt program remotely to your database? Using something like this:
mysql -h <your remote ip> -u <your db user> -p