PDA

View Full Version : Can't connect to MySQL server on '192.xxx.x.x' (111) QMYSQL: Unable to connect



shawshank
26th January 2014, 06:57
I am trying to sync two databases using a local IP. Though I have the QMYSQL driver installed properly it still gives an error for connection failed.
A main database is created on host computer and I'm trying to sync data from another computer to this database through a local network.
Code on host computer:


QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL","Host");
db.setHostName("HOSTIP");
db.setDatabaseName("test");
db.setUserName("root");
db.setPassword("toor");

Code on other computer:


QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL","Other");
db.setHostName("IP OF HOST");
db.setDatabaseName("test");
db.setUserName("root");
db.setPassword("toor");

Any help is appreciated!!

ChrisW67
26th January 2014, 07:57
Are the Mysql servers configured to accept connections via IP (i.e. skip_networking not im my.cnf, bind-address not restricting)? Can you connect using those credentials with the Mysql command line tools (i.e. without Qt)?

shawshank
26th January 2014, 16:57
I have never configured MySql with Qt. This is my first attempt. Could you tell me how to check if MySql servers are configured to accept connections via IP?

ChrisW67
26th January 2014, 21:58
Configuring the Mysql server has nothing to do with Qt. Try connecting from one of the machines using the tools supplied with mysql first:

mysql -h 192.a.b.c -u root -p test
If that doesn't work then the problem also has nothing to do with Qt.

The Mysql server configuration is in a file called my.cnf which may be in any number of locations (often /etc/mysql/my.cnf but YMMV). The two obvious options to check in that file are bind-address (should include 192.a.b.c) and skip-networking (should be absent/commented) in the "[mysqld]" group
http://dev.mysql.com/doc/refman/5.6/en/option-files.html
http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html

shawshank
27th January 2014, 09:17
Thanks for your reply!!
I tried using the MySql tools to connect with the database on the other IP. But it still gives the same error on the terminal.
Could you please tell me how to configure the MySql server? I can't understand how to change the values of bind-address and skip-networking.

ChrisW67
27th January 2014, 22:22
You change the values with a text editor after stopping the MySql server. Find the section labelled "[mysqld]", comment out the skip-networking line if present, change the bind-address line to:


[mysqld]
...

# Commented out
# skip-networking

# Wide open, listens on all interfaces
bind-address 0.0.0.0
# Or more restricted, listen only on specified interface
bind-address 192.168.1.1

Beyond that I suggest you go back to MySql sources. This has nothing to do with Qt.