Home > Database > Mysql Tutorial > body text

Why am I getting 'mysqli_connect(): (HY000/2002): Connection refused' in PHP with MAMP?

DDD
Release: 2024-11-08 07:43:01
Original
746 people have browsed it

Why am I getting

PHP Connection Refusal: "mysqli_connect(): (HY000/2002): Connection refused"

When encountering the error "mysqli_connect(): (HY000/2002): Connection refused" while using PHP and MAMP, there is a discrepancy between the default port configurations.

Troubleshooting:

  1. Check MAMP MySQL port: By default, MAMP uses port 8889 for MySQL, while PHP typically expects port 3306.
  2. Modify MAMP port: Open MAMP preferences and change the MySQL port to 3306.
  3. Restart MySQL server: After making the port change, it's essential to restart the MySQL server within MAMP.
  4. Reconfigure connection: Modify your PHP script to use the host 'localhost,' username 'root,' and password 'root' while establishing the connection. This configuration should now be successful.

Note: Some older versions of PHP may require explicit port specification when connecting to MySQL. In this case, include ':3306' after the hostname in the connection string (e.g., '$servername = "127.0.0.1:3306";').

The above is the detailed content of Why am I getting 'mysqli_connect(): (HY000/2002): Connection refused' in PHP with MAMP?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template