简体   繁体   中英

Public IP Address as my hostname in mysql_connect()

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.

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';

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.

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';

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM