You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MAMP环境下phpMyAdmin数据库连接失败求助(错误码HY000/1045)

Fixing "Access denied for user 'root'@'localhost'" in MAMP

Hey there, let's work through this MySQL connection issue in MAMP—since you've already checked the basics like credentials and permissions, let's focus on MAMP-specific quirks that often trip people up:

1. Double-check MAMP's MySQL Port

MAMP doesn’t use the default 3306 port for MySQL by default—it usually uses 8889. When you tried localhost:3306, you might’ve been targeting a system-wide MySQL instance (if installed) instead of MAMP’s own database server.

  • Open MAMP and look at the main interface: you’ll see the MySQL port listed right next to the "Start Servers" button.
  • Update your connection code to use that port. For example, if the port is 8889:
    $mysql_hostname = "localhost:8889";
    $mysql_user = "root";
    $mysql_password = "mypassword";
    $mysql_database = "mydatabase";
    $prefix = "";
    // Combine connection and database selection into one step for simplicity
    $bd = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password, $mysql_database) or die("Could not connect database");
    

2. Confirm Permissions Are Actually Applied

Sometimes granting permissions in phpMyAdmin doesn’t take effect right away. Let’s make sure the changes stick:

  • Open phpMyAdmin, go to the User accounts tab.
  • Find the root@localhost user, click Edit privileges.
  • Ensure all privileges are checked, then click Go to save.
  • Restart MAMP’s MySQL service (stop and start servers again) to refresh the permission cache.

3. Test Credentials Directly via MAMP's MySQL Terminal

Let’s rule out password mismatches by testing directly in the terminal:

  • In MAMP, click Open start page → navigate to Tools → MySQL Terminal.
  • When prompted, run this command and enter your password when asked:
    mysql -u root -p
    
  • If you can log in successfully, your credentials are correct—so the issue is in how your PHP code is connecting. If you can’t log in, reset the root password in phpMyAdmin:
    1. Go to User accounts → select root@localhost → Edit privileges.
    2. Scroll to Change password, enter mypassword (match what’s in your code), and save.

4. Ensure You're Connecting to MAMP's MySQL Instance

If you have a system-wide MySQL installed, your PHP might be trying to connect to that instead of MAMP’s. To confirm:

  • Check that MAMP’s MySQL process is running (look for the green light in the MAMP interface).
  • Verify your PHP environment uses MAMP’s PHP (not the system’s): create a phpinfo.php file with <?php phpinfo(); ?>, access it via MAMP’s local server (e.g., http://localhost:8888/phpinfo.php), and check the mysqli section for the MySQL port—it should match MAMP’s port.

内容的提问来源于stack exchange,提问作者Manuel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:26:02