gpt4 book ai didi

mysql - macOS 10.15 Catalina 上的 Homebrew MySQL 8.0.18 无法作为服务运行

转载 作者:行者123 更新时间:2023-11-29 01:05:15 35 4
gpt4 key购买 nike

另一个 macOS 升级 + 另一个 MySQL 升级 = 另一组问题。

我似乎无法让 MySQL 8.0.18 在 macOS 10.15 Catalina 上作为 Homebrew 服务运行。请告诉我错误的方法。

这是我所做的:

  1. brew 安装mysql
  2. 烧写mysql
  3. 触摸/tmp/mysql.sock
  4. mysql.server 启动
  5. 取消设置 TMPDIR
  6. mysql_secure_installation
  7. mysql.server 停止
  8. sudo brew services 启动mysql

这是我的预期:

MySQL 以用户 root 身份作为 Homebrew 服务愉快地运行。

事情是这样的:

MySQL 立即崩溃并死掉,在 /usr/local/var/mysql/[host.domain.com].err 中留下一个神秘的最后语句:

"[ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!"

附加信息:

MySQL 在随后的重启中运行良好只要我手动启动它:

sudo reboot now
ssh [servername.domain.com]
touch /tmp/mysql.sock
mysql.server start

这是 /usr/local/var/mysql/[servername.domain.com].err 文件内容:

2019-10-20T18:02:14.6NZ mysqld_safe Logging to '/usr/local/var/mysql/moriarty.farces.com.err'.
2019-10-20T18:02:14.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2019-10-20T18:02:14.670494Z 0 [System] [MY-010116] [Server] /usr/local/Cellar/mysql/8.0.18/bin/mysqld (mysqld 8.0.18) starting as process 557
2019-10-20T18:02:14.685511Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2019-10-20T18:02:15.617696Z 0 [System] [MY-010229] [Server] Starting crash recovery...
2019-10-20T18:02:15.626461Z 0 [System] [MY-010232] [Server] Crash recovery finished.
2019-10-20T18:02:15.795626Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-10-20T18:02:15.833541Z 0 [System] [MY-010931] [Server] /usr/local/Cellar/mysql/8.0.18/bin/mysqld: ready for connections. Version: '8.0.18' socket: '/tmp/mysql.sock' port: 3306 Homebrew.
2019-10-20T18:02:15.993739Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/tmp/mysqlx.sock' bind-address: '127.0.0.1' port: 33060

重启后,当我尝试将 MySQL 作为 Homebrew 服务运行时:

sudo reboot now
ssh [servername.domain.com]
sudo brew services start mysql

MySQL 失败,/usr/local/var/mysql/[servername.domain.com].err 文件中记录了以下错误:

2019-10-20T18:44:13.780394Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2019-10-20T18:44:13.780503Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-10-20T18:44:13.780727Z 0 [System] [MY-010910] [Server] /usr/local/opt/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.18) Homebrew.
2019-10-20T18:44:13.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/moriarty.farces.com.pid ended

最佳答案

切勿将 sudo 与命令 brew 一起使用。它会破坏相关文件的所有权。不支持以 root 身份运行 brew。 (我说的是brew,不是mysqld)

Quote from Homebrew doc

tl;dr Sudo is dangerous, and you installed TextMate.app without sudo anyway.

Homebrew refuses to work using sudo.

来自 source code of brew 的警告

check-run-command-as-root() {
...
odie <<EOS
Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
EOS
}

解决方案

  1. 禁用该服务并删除启动守护进程。

    # stop and unload the launchdaemon
    sudo launchctl unload -w /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
    # remove the lauchdaemon file
    sudo rm -f /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
    sudo rm -f /tmp/mysql.sock /tmp/mysqlx.sock
  2. 修复 Homebrew 软件相关文件的所有权

    # For x86 Mac
    sudo chown -R "$(whoami):admin" /usr/local/*
    # For M1 Mac
    sudo chown -R "$(whoami):admin" /opt/homebrew/*
    # it will take some time
  3. 重新启用 MySQL 服务。

    # DO NOT USE "sudo brew"
    brew services start mysql

更新:

似乎你们中有些人不熟悉 Homebrew。我将在此处解释 Homebrew 如何管理服务。

mysqld 默认监听端口 3306,这不是特权端口。所以不需要用root启动mysqldsystemd 在 Linux 上以 root 启动 mysqld,但 macOS 不是 Linux。

Homebrew 在 launchd 的帮助下管理服务,它是 macOS 上的 systemd 替代品。 launchd 启动一个前台进程并为您管理它,就像 systemd 所做的那样。

brew services start/stop mysql 将满足您的需要。它创建一个 launchd 文件 ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist,用它启动 mysqld(由当前用户运行)。

/usr/local/mysql/support-files/mysql.server是MySQL自带的shell脚本,可以帮助你启动mysqld。不推荐直接使用它,除非您从外部 Homebrew 源构建MySQL。如果您使用 Homebrew,请坚持使用 brew services。或者换句话说,如果你使用 Homebrew,你应该以 Homebrew 的方式做事。

关于mysql - macOS 10.15 Catalina 上的 Homebrew MySQL 8.0.18 无法作为服务运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58466272/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com