I have database MySQL in my XAMPP server in Machine-1 [where] I don’t have problem. But when I move my project and database to [an]other XAMPP server, Machine-2, I get message:
Warning: mysqli_connect(): (HY000/2002): 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.
and this is code for php-MySQl Connection
$database['host'] = '192.168.1.*'; //ip address here $database['user'] = 'root'; $database['password'] = ''; $database['dbname'] = 'db'; $connect = mysqli_connect($database['host'], $database['user'], $database['password'], $database['dbname']);
$database['host'] = '*.*.*.*'; //ip address here changed for security $database['user'] = 'root'; $database['password'] = ''; $database['dbname'] = 'db'; $connect = mysqli_connect($database['host'], $database['user'], $database['password'], $database['dbname']);
How can it happen in Machine-1 I haven’t problem, but in Machine-2 I can’t connect to mySQL?
Depending on the configuration of the second machine, you might have issues with:
- A firewall blocking access to the database port (either hardware or
- An IP issue if you’re using these machines on a local
network with the second IP you’ve provided.
- A subnet mask issue if
you’re on a LAN with the machines disconnected from the Internet.
- A configuration issue if your MySQL server doesn’t allow outside
- Check your logs.
- Try to telnet to the port you’ve setup for MySQL (3306?)
- Try to ping the IP and trace the route to see if something is blocking your connection.
- If you’ve tried multiple attempts to connect and are running something like IPtables on the 2nd server it can block your IP for too many hits.
- Make sure on the second server you’re not blocking it with something like SE Linux (that can take forever to figure out).
Check the value of
on the server machine. You must allow specified networks or ip address to connect remotely to mysql server. Also you should grant user privileges bases on the [email protected]