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

Mac系统下MySQL安装后无法登录问题求助

Fixing MySQL Access Denied Error After Brew Installation

Hey there, I totally get how frustrating this is—brew-installed MySQL has a quirk where the root user often uses socket authentication by default instead of password-based, even if you set a password initially. Let's walk through fixing this step by step:

Step 1: Stop the Running MySQL Service

First, make sure MySQL isn't running in the background:

brew services stop mysql

Step 2: Start MySQL in Safe Mode (Bypass Authentication)

We'll launch MySQL with a flag that skips permission checks, so we can log in without a password:

mysqld_safe --skip-grant-tables &

Step 3: Log Into MySQL Without Password

Now you can access the MySQL shell directly:

mysql -uroot

Step 4: Update Root User's Authentication & Password

Switch to the system mysql database, then update the root user to use password authentication and set a new password (replace your-secure-password with your desired password):

USE mysql;
UPDATE user 
SET authentication_string=PASSWORD('your-secure-password'), 
    plugin='mysql_native_password' 
WHERE User='root' AND Host='localhost';
FLUSH PRIVILEGES;
EXIT;

Note: Using mysql_native_password ensures compatibility with most standard login methods, which avoids the "access denied" errors you're seeing.

Step 5: Restart MySQL Normally

First shut down the safe-mode instance, then start the service back up:

mysqladmin -uroot -p shutdown
# Enter your new password when prompted
brew services start mysql

Step 6: Test the Login

Now try logging in again—this should work:

mysql -uroot -p

You can also test the sudo variant if needed, and it should recognize your new password now.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:28:38