Why can't I connect to mySQL database using php?

Asked 2 years ago, Updated 2 years ago, 53 views

We use MAMP to develop applications.
Initially, it was implemented on MacOS, and php implemented the general process of accessing MySQL-Database.
After that, I deployed MAMP to Windows PC and applied the same script to verify that it worked fine, but when I applied MAMP and scripts to the production Windows PC, the following error occurred and I couldn't connect to the MySQL database:

Warning:mysqli_connect():(HY000/2003):Can't connect to MySQL server on 'localhost' (10061) in C:\MAMP\htdocs\xxxx.php on line 100 error::2003

I found a similar situation and how to deal with it online, and I tried it, but I couldn't see any improvement.

Could you give me some advice on the reason for the defect and how to deal with it?
Thank you for your cooperation.

Below is the response I have tried.
·Changing the port number (On the MAMP configuration screen, it says Apatch:8888 MySQL:8889).
·Reinstall
·Pause real-time scanning of security software
·Login to the server → I tried to access it with my root account, but I couldn't log in.

As I am not familiar with the server, I may have misplaced the port number.

php mysql

2022-09-30 14:30

1 Answers

MySQL service is not started
→ Start
MySQL is not configured for network connectivity
→ Set up a network connection
The port MySQL listens to and the port specified in the script do not match
→ Match the port numbers
Blocked by Windows Firewall
→ Add Windows Firewall Settings


2022-09-30 14:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.