1

i want to connect my php application(here at my office) and my database is at my home,

mysql_connect('119.92.59.55','root','lester1992') 

but they don't communicate each other(my comp & my office terminal), what maybe the posible problem?

here is the error i encountered.

mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

thanks in advance.

Lester1992
  • 493
  • 2
  • 9
  • 20
  • http://stackoverflow.com/questions/16287559/mysql-adding-user-for-remote-access will helpful – Girish Feb 26 '14 at 05:54
  • 2
    Is the database actually reachable over the public internet? Are the ports open and properly forwarded? Actually, one would hope they are not. Putting a MySQL server on the public internet is a bad idea, unless you really know what you're doing and have set everything up very securely. – deceze Feb 26 '14 at 05:57
  • in mysql the authentication is host based. you should give permission for the office computer. – bansi Feb 26 '14 at 05:58
  • sir Girish Jangid i tried this already, but the problem i can't start my mysql :( – Lester1992 Feb 26 '14 at 06:11
  • try `telnet your-home-ip 3306` if it is able to connect you have proper port forwarding in your router at home otherwise check router and firewall at your home to see if the connection to port 3306 is forwarded to the computer running MySQL server. (assuming you have not changed the default MySQL port). Also note changing the MySQL port used is better because you are putting it in the open. – bansi Feb 26 '14 at 06:14
  • sir bansi, i dont know how to telnet :D – Lester1992 Feb 26 '14 at 06:47

4 Answers4

1

You need to give access permission in mysql to access from remote host.

GRANT ALL PRIVILEGES
ON database.*
TO 'user'@'your_office_ip_address'
IDENTIFIED BY 'newpassword';
SajithNair
  • 3,867
  • 1
  • 17
  • 23
0

To connect to a MySQL database, three things must meet:

  • Login
  • Password
  • Host

By default, root is configured to allow connections from the hostname localhost only. You can edit the table mysql.user and change root's Host to % to allow connections from any peer.

UPDATE mysql.user SET Host = '%' WHERE User = 'root';

Don't forget to run FLUSH PRIVILEGES after that change in order to make it take effect immediately.

In addition, your firewall and router must be configured to make connections to port 3306 possible. You can use an online test tool such as this one to check if your port 3306 is reachable.

Havenard
  • 27,022
  • 5
  • 36
  • 62
0

By default, mysql is not allowing your user from your IP.

You want to allow access with a command similar to this (keep in mind this is very insecure):

GRANT ALL PRIVILEGES
ON database.*
TO 'root'@'119.92.59.55'
IDENTIFIED BY 'lester1992';
Derek Nutile
  • 211
  • 3
  • 10
0

If you don't want to open your db for all ip's then you should assign rights to specific ip.

GRANT ALL PRIVILEGES ON db.* TO 'user'@'your_office_ip' IDENTIFIED BY 'newpassword';

Note: You can get your office ip by below link, it will show you your current ip:

http://www.whatismyip.com/

Zafar Malik
  • 6,734
  • 2
  • 19
  • 30