最近,我的 Homebrew MySQL 设置在尝试启动时开始失败。当我运行 时mysql.server start
,出现以下错误:
$ mysql.server start
Starting MySQL
.. ERROR! The server quit without updating PID file (/opt/homebrew/var/mysql/MacBookPro.pid).
以下是来自的日志/opt/homebrew/var/mysql/${computer_name}.err
:
2025-01-01T22:08:13.6NZ mysqld_safe Logging to '/opt/homebrew/var/mysql/MacBookPro.err'.
2025-01-01T22:08:13.6NZ mysqld_safe Starting mysqld daemon with databases from /opt/homebrew/var/mysql
2025-01-01T22:08:13.378645Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2025-01-01T22:08:13.521513Z 0 [System] [MY-010116] [Server] /opt/homebrew/opt/mysql/bin/mysqld (mysqld 9.0.1) starting as process 40612
2025-01-01T22:08:13.522727Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /opt/homebrew/var/mysql/ is case insensitive
2025-01-01T22:08:13.536732Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-01-01T22:08:13.583485Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-01-01T22:08:13.716166Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2025-01-01T22:08:13.716195Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2025-01-01T22:08:13.719572Z 0 [ERROR] [MY-000067] [Server] unknown variable 'default_authentication_plugin=mysql_native_password'.
2025-01-01T22:08:13.720023Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-01-01T22:08:14.884732Z 0 [System] [MY-010910] [Server] /opt/homebrew/opt/mysql/bin/mysqld: Shutdown complete (mysqld 9.0.1) Homebrew.
2025-01-01T22:08:14.884778Z 0 [System] [MY-015016] [Server] MySQL Server - end.
2025-01-01T22:08:14.6NZ mysqld_safe mysqld from pid file /opt/homebrew/var/mysql/MacBookPro.pid ended
有趣的是下面这一行,这似乎就是问题所在:
2025-01-01T22:08:13.719572Z 0 [ERROR] [MY-000067] [Server] unknown variable 'default_authentication_plugin=mysql_native_password'.
这里是my.cnf
:
# Default Homebrew MySQL server config
[mysqld]
default_authentication_plugin= mysql_native_password
# Only allow connections from localhost
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
另一个数据点是,如果我运行mysql.server stop
,我会收到此错误:
$ mysql.server stop
ERROR! MySQL server PID file could not be found!
这是我的 MySQL 版本:
$ mysql --version
mysql Ver 9.0.1 for macos15.1 on arm64 (Homebrew)
我在 M1 MacBook Pro 上运行 macOS Sequoia 15.2。
有很多类似的帖子,但似乎都没什么帮助。如果可能的话,我也不想删除我的数据库,而是重新开始。
有人知道是什么原因造成的,以及如何解决它吗?这可能是因为 MySQL 9 不支持吗default_authentication_plugin=mysql_native_password
?
我在自己的设置中遇到了类似的问题。关键是您的 MySQL 版本无法识别
default_authentication_plugin=mysql_native_password
中的行my.cnf
。MySQL 8 使用了该参数,但在 MySQL 9 中,它似乎已更改或被删除。解决此问题的最简单方法是打开
/opt/homebrew/etc/my.cnf
(或无论您my.cnf
身在何处),删除或注释掉该default_authentication_plugin
行,然后尝试重新启动 MySQL。您也可以将其明确设置为 MySQL 9 正式支持的任何插件(caching_sha2_password
现在是典型的默认设置),但快速测试是注释掉该行并查看 MySQL 是否能正常启动。如果这不起作用,请确保您使用的是同一版本的 MySQL — Homebrew 有时会留下旧 MySQL 安装的残留。执行以下操作可能会有所帮助:
然后确保符号链接设置为正确的版本。如果 MySQL 仍然拒绝启动,您可以尝试
/opt/homebrew/var/mysql
暂时将数据目录(文件夹)移开,让 MySQL 重新初始化新的数据目录,然后恢复数据。但通常情况下,只需删除或更新该default_authentication_plugin
行即可解决启动时崩溃的问题。