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

macOS安装MySQL v8.0.11后root@localhost访问被拒绝求助

Fixing "Access denied for user 'root'@'localhost'" on MySQL 8.0.11 (macOS High Sierra 10.13.4)

Hey there, I’ve dealt with this exact issue when setting up MySQL 8.0 on High Sierra—let’s walk through the fix step by step. The key thing to know is MySQL 8.0 generates a temporary root password automatically during installation (you didn’t miss a step, it just doesn’t prompt you for it upfront!).

Step 1: Locate the temporary root password

MySQL stores the initial temporary password in its error log. Here’s how to grab it quickly:

  • Open Terminal and run this command to search the log for the password:
    cat /usr/local/mysql/data/$(hostname).err | grep "temporary password"
    
    You’ll see a line like: [Note] A temporary password is generated for root@localhost: XXXXXXXXXX
  • Copy that random string (it might include special characters like ! or #—don’t worry, just copy it as-is).

Step 2: Log in with the temporary password

Now use that password to access MySQL:

  • Run this command in Terminal:
    mysql -u root -p
    
  • When prompted, paste the temporary password you copied and hit Enter. You should now be inside the MySQL shell.

Step 3: Set a new root password

Once logged in, you’ll need to replace the temporary password with one you remember. MySQL 8.0 enforces password complexity by default, so pick a password with at least 8 characters, including uppercase, lowercase, numbers, and a special character.

  • Run this SQL command (replace your-new-password with your chosen password):
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'your-new-password';
    
  • If you want a simpler password for local testing (not recommended for production!), first loosen the password policy:
    SET GLOBAL validate_password.policy = LOW;
    SET GLOBAL validate_password.length = 6;
    
    Then run the ALTER USER command again with your simpler password.

Step 4: Verify the fix

Exit the MySQL shell with:

exit;

Then try logging in again with your new password:

mysql -u root -p

Enter your new password, and you should be logged in successfully.

Troubleshooting tip

If you run into issues with the MySQL service (like needing to restart it), you can:

  • Use the MySQL preference pane in System Preferences to stop/start the service.
  • Or use Terminal commands:
    sudo /usr/local/mysql/support-files/mysql.server stop
    sudo /usr/local/mysql/support-files/mysql.server start
    

内容的提问来源于stack exchange,提问作者Faheem Hassan Zunjani

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:25:07