13

我需要使用 M1 在我的 MacBook 上安装特定版本的 MySQL (5.7)。

我正在尝试使用 Homebrew 来做到这一点。

brew install mysql@5.7

输出:

We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

mysql@5.7 is keg-only, which means it was not symlinked into /opt/homebrew, because this is an alternate version of another formula.

If you need to have mysql@5.7 first in your PATH, run:   echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc

For compilers to find mysql@5.7 you may need to set:   export LDFLAGS="-L/opt/homebrew/opt/mysql@5.7/lib"   export CPPFLAGS="-I/opt/homebrew/opt/mysql@5.7/include"


To have launchd start mysql@5.7 now and restart at login:   brew services start mysql@5.7 Or, if you don't want/need a background service you can just run:   /opt/homebrew/opt/mysql@5.7/bin/mysql.server start

在那之后,我尝试运行:

echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
source .zshrc
mysql_secure_installation

并得到错误:

Securing the MySQL server deployment.
Enter password for user root: 
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

另外,我试过: brew services start mysql@5.7

并且还得到错误:

Error: Permission denied @ rb_sysopen - /Users/vivanc/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist

似乎存在与权限相关的问题。任何建议表示赞赏。

4

6 回答 6

6

如果您遇到“ Can't connect to local MySQL server through socket '/tmp/mysql.sock'”或“ The post-install step did not complete successfully MySQL”之类的问题,并且您之前安装了以前版本的 mysql(例如 8.x),那么您可能需要在重新安装首选版本的 mysql@ 之前清理所有内容xx

如果您已经访问过这些链接: 卸载所有损坏的 MySQL 版本并在 Mac Mavericks (Coderwall) 上使用 Brew 重新安装它+在 macOS 上使用 Homebrew (github) 安装 MySQL 5.7并且您仍然无法启动您的 mysql-service,您应该尝试也删除/opt/homebrew/etc/my.cnf文件。

也将其与所有相关文件一起删除!M1 Apple Silcion机器总结,通过brew uninstall mysql或卸载后brew uninstall mysql@x.x,请删除:

/opt/homebrew/var/mysql
/opt/homebrew/etc/my.cnf

在此之后,一切都像全新安装一样(对我而言)。希望这节省了某人的时间。

于 2021-10-30T18:05:59.660 回答
5

经过数小时的搜索,我解决了这个问题,这是因为我没有清理我之前安装的 MySQL 8.X 的所有内容。当我意识到我那里没有大部分文件夹时,我跟着这个并开始怀疑。然后,我搜索了mysql我计算机上命名的所有文件夹,并mysqlopt/homebrew/var. 删除它后,重新安装 MySQL 5.7,并启动服务器,一切都按预期工作。

于 2021-03-15T13:05:16.077 回答
2

When setting up my Apple M1 Macbook Pro I was experiencing the issue of the following error message being thrown:

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

My fix was to modify the MySQL config file:

nano /usr/local/etc/my.cnf

Append the following lines:

tmpdir=/tmp
user=root

Then run:

brew services restart mysql@5.7

This fixed my issue, and I was then able to connect successfully with my DB client.

于 2021-05-24T08:52:15.700 回答
2

虽然这个问题特定于 Apple Silicon 和 mysql 5.7,我将在这个答案中解决这个问题,但我想首先添加一些一般性注释以节省其他时间:

Homebrew 支持英特尔和苹果芯片的 mysql 5.7。 https://formulae.brew.sh/formula/mysql@5.7

Homebrew 支持英特尔芯片的 mysql 5.6,但不支持苹果芯片: https ://formulae.brew.sh/formula/mysql@5.6

如果您需要苹果芯片上的 5.6,那么只解决 5.7 可能是一个好主意,因为最终需要升级生产并且差异不是那么大。

在我最初的情况下brew install mysql,它给了我最新的mysql(目前是8.0)。当我尝试回过头来做brew install mysql@5.6时,当然这不起作用,因为 m1 max(苹果硅)不支持。我遇到了问题,然后试图开始brew install mysql@5.7工作。我遵循了一些指南,提到了各种建议。在玩了一段时间之后,似乎同时运行两个版本的 mysql 会损坏您的 mysql 文件,使其难以使用并混淆自制软件。

我遇到了这些指南:
brew install mysql on macOS
https://coderwall.com/p/os6woq/uninstall-all-those-broken-versions-of-mysql-and-re-install-it-with-brew-on -mac-mavericks
https://www.codegrepper.com/code-examples/shell/brew+uninstall+mysql

在进一步阅读之前,请注意在我的情况下,我有一个 zip 可用于我的整个本地 mysql 数据库需求,并且可能会破坏我所拥有的。

警告!进一步阅读并不小心执行这些命令可能会删除您的 mysql 存储。确保您有备份。

brew remove mysql是一个很好的命令,它摆脱了我最新的安装。即使这是我正在尝试安装的版本,我也需要brew remove mysql@5.7,但他们正在互相踩踏......

brew cleanup很好,我注意到它释放了一些锁定文件。

我不记得有什么运气: launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist 但你可以试试。

rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist对我有用。但请注意,您的 5.7 设置中还会有另一个文件。我建议: cd ~/Library/LaunchAgents/然后环顾四周,看看那里是否有任何 mysql*。然后,如果您这样做,例如homebrew.mxcl.mysql@5.7.plist,则将其删除。

这些对我有用:

sudo rm -rf /usr/local/var/mysql
rm /usr/local/etc/my.cnf
rm /usr/local/etc/my.cnf.default

还:

cd opt/homebrew/var

然后,如果您注意到那里有一个 mysql 目录,请将其删除。

您可能有 docker 或其他类似的东西也在运行 mysql 或 mysqld。
ps -ax | grep "[m]ysql"
(注意上面的括号和引号是为了防止 grep 出现在进程列表中并与惰性版本不同:ps -ax | grep mysql这会让人觉得有一个额外的 mysql 进程正在运行)

一旦你准备好了,请运行: brew services list 仔细检查你那里没有mysql。然后仔细检查您没有运行任何 mysql 进程:
ps -ax | grep "[m]ysql" 例如,如果您输入 example....,则可能会发生这种情况。如果您在服务列表或进程列表上看到任何内容,mysqld您可能需要执行brew services stop mysql或类似操作并重复步骤。brew services stop mysql@5.7

最后,您应该准备好进行全新安装。全新的安装过程应该相当简单:

brew install mysql@5.7
brew link --force mysql@5.7
brew services start mysql@5.7

然后运行brew services list以确保您的安装工作正常。如果您看到它是绿色的并且“已启动”,那么您的安装成功了!

您还应该运行: mysql_secure_installation 然后为 root 选择一个密码,并通过验证等问题列表。

安装后,您可能还会遇到 mysql 模式问题。 cd /opt/homebrew/etc你应该找到一个 my.cnf 文件。使用 vim 或 nano 编辑它。您应该会看到如下内容:

# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1

编辑它并设置mysql模式。例如,我不想要 no_zero_in_date 模式,所以我使用:

# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
sql-mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

然后像这样重启mysql:
brew services restart mysql@5.7

然后仔细检查你仍然有一个绿色状态“开始”:
brew services list
如果你这样做了,那么你应该禁用 no_zero_in_date 模式。
您可以使用查询对其进行测试:
SELECT @@sql_mode;

您现在应该在 Apple Silicon 上运行 mysql 5.7 并设置 sql_mode。

如果您遇到更多故障排除,请尽力进入已知状态,例如已卸载、重新安装或已安装某个版本等。

于 2021-12-07T08:41:13.613 回答
1

好像我找到了解决方案(或解决方法)。

使用 Homebrew 安装 MySQL 5.7 后,只需运行:

mysql.server start

MySQL 启动,然后您可以运行mysql_secure_installationmysql命令。

于 2021-03-16T15:30:45.457 回答
1

我收到了这个警告:

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1

And make sure that your user has write permission.
  chmod u+w /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1

我运行这两个命令然后它工作。

于 2021-05-18T09:10:00.247 回答