


What Causes the 'mysqli_connect(): Connection Refused' Error in PHP and How to Fix It?
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:
- Open MAMP's preferences by selecting "Preferences" from the menu bar.
- In the "Ports" tab, change the "MySQL" port to 3306.
- Click "OK" to save the changes.
-
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Reduce the use of MySQL memory in Docker

How do you alter a table in MySQL using the ALTER TABLE statement?

How to solve the problem of mysql cannot open shared library

Run MySQl in Linux (with/without podman container with phpmyadmin)

What is SQLite? Comprehensive overview

Running multiple MySQL versions on MacOS: A step-by-step guide

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?

How do I configure SSL/TLS encryption for MySQL connections?
