




Homebrew安装MySQL后服务无法启动的四大原因及解决:权限错误需chown修复;认证插件不兼容应升级客户端或指定mysql_native_password;配置文件应放/usr/local/etc/my.cnf;升级前须备份数据并用mysql_upgrade迁移。
常见现象是执行 brew services start mysql 或 mysql.server start 后报错,提示 ERROR! The server quit without updating PID file,或日志里出现 Can't start server: Bind on TCP/IP port: Address already in use。
ps aux | grep mysql,若有残留进程(如 mysqld),用 kill -9 清掉grep 'temporary password' /usr/local/var/mysql/*.err
/usr/local/var/mysql 目录权限不对 —— Homebrew 安装后该目录属主应为当前用户,执行 sudo chown -R $(whoami) /usr/local/var/mysql 再试这不是密码输错,而是 MySQL 8.0 默认使用 caching_sha2_password 认证插件,而部分客户端(尤其是老版本命令行工具或某些 GUI)不兼容。
mysqld_safe --skip-grant-tables &,然后连上执行 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password';
brew uninstall mysql,再用自定义配置安装:brew install mysql --with-default-authentication-plugin=mysql_native_password(注意:该 flag 在较新 Homebrew 中已移除,推荐改用下一步)

mysql -u root -p --default-auth=mysql_native_password
Homebrew 不会自动创建 my.cnf,所有配置靠默认路径加载顺序生效。MySQL 8.0 在 macOS 上按如下顺序读取配置文件:/etc/my.cnf → /usr/local/etc/my.cnf → ~/.my.cnf。
/usr/local/etc/my.cnf(Homebrew 推荐);若该文件不存在,手动创建:sudo touch /usr/local/etc/my.cnf
[mysqld] bind-address = 0.0.0.0 max_connections = 200 character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci [client] default-character-set = utf8mb4
brew services restart mysql,否则配置不生效Homebrew 升级 MySQL(如从 8.0.x → 8.1.x)默认不会迁移数据目录,旧版 /usr/local/var/mysql 若存在,新版可能拒绝启动或初始化失败。
mysqldump -u root -p --all-databases > full_backup.sql
/usr/local/var/mysql —— 先确认新版本是否已新建数据目录(如 /usr/local/var/mysql@8.1),再用 mysql_upgrade -u root -p 手动迁移brew uninstall mysql && rm -rf /usr/local/var/mysql,但此操作不可逆/usr/local/var/mysql 这个目录的归属权和 my.cnf 的实际加载位置,它们比任何文档都真实。