PHP Warning: mysqli_connect(): Connection Refused (HY000/2002)
This error occurs when PHP fails to establish a connection to the MySQL database. The cause is indicated by the error code "HY000/2002," which typically signifies that the connection was refused due to incorrect server configuration.
To resolve this issue, verify the following settings within MAMP:
MySQL Server
Ensure that the MySQL server is running. In MAMP, this can be done by selecting the "Start MySQL Server" option from the menu bar.
MySQL Port
The default MySQL port used by MAMP is 8889. However, PHP typically uses port 3306 by default. To resolve this conflict:
Database Credentials
Verify that the host ("127.0.0.1"), username ("root"), and password ("root") specified in the PHP script are correct.
After making these adjustments, restart the MySQL server in MAMP. Reconnecting should now be successful with the host, user, and password as specified in the PHP script.
The above is the detailed content of What Causes the 'mysqli_connect(): Connection Refused' Error in PHP and How to Fix It?. For more information, please follow other related articles on the PHP Chinese website!