如何使用Homebrew在macOS BigSur(Apple Silicon)上安装和启动MySQL 5.7?

jgwigjjp  于 4个月前  发布在  Mysql
关注(0)|答案(6)|浏览(82)

我需要一个特定版本的MySQL(5.7)安装在我的MacBook与M1。
我正在尝试用Homebrew来做这件事。
第一个月
输出:

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

[email protected] 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 [email protected] first in your PATH, run:   echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

For compilers to find [email protected] you may need to set:   export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"   export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"

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

字符串
在那之后,我试着跑:

echo 'export PATH="/opt/homebrew/opt/[email protected]/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 [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)
并得到错误:

Error: Permission denied @ rb_sysopen - /Users/vivanc/Library/LaunchAgents/[email protected]


似乎有一个与许可证有关的问题。任何建议都很感激。

z8dt9xmd

z8dt9xmd1#

如果你遇到了像“Can't connect to local MySQL server through socket '/tmp/mysql.sock'“或“The post-install step did not complete successfully MySQL“这样的问题,并且你之前安装了一个mysql的早期版本(例如8.x),那么在重新安装你喜欢的email protected(https://stackoverflow.com/cdn-cgi/l/email-protection)版本之前,你可能需要清理所有的东西。
如果你已经访问了这些链接:Uninstall all those broken versions of MySQL and re-install it with Brew on Mac Mavericks (Coderwall) + Install MySQL 5.7 on macOS using Homebrew (github),并且你仍然无法启动你的mysql服务,你应该尝试也删除/opt/homebrew/etc/my.cnf文件。
将其连同所有相关文件一起删除!M1 Apple Silicon机器摘要,通过brew uninstall mysqlbrew uninstall [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)卸载后,请删除:

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

字符串
在这之后,一切都像一个新的安装(对我来说)。希望这节省了一些人的时间。

sqyvllje

sqyvllje2#

虽然这个问题是针对Apple Silicon和mysql 5.7的,我将在这个答案中解决这个问题,但我想先添加一些一般性的注意事项,以保存其他人的时间:
Homebrew支持mysql 5.7,适用于intel和apple silicon。https://formulae.brew.sh/formula/[email protected]
Homebrew支持mysql 5.6的英特尔芯片,但不支持苹果芯片:https://formulae.brew.sh/formula/[email protected]
如果你需要5.6版的苹果芯片,那么最好还是选择5.7版,因为生产最终需要升级,而两者的差别并不大。
在我的情况下,我最初做了brew install mysql,它给了我最新的mysql(目前是8.0)。当我试着回去做brew install [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)时,当然这不起作用,因为在m1 max上不支持。(苹果硅)。我遇到了问题,然后试图让brew install [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)工作。我遵循了一些指南提到各种建议。玩了一段时间后,看起来同时运行两个版本的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 [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection),即使这是我试图安装的版本,但他们踩在对方的脚。
brew cleanup很好,我注意到它释放了一些锁定文件。
我不记得有任何运气:launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist,但你可以试试。
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist已经为我工作了。但是注意,在5.7安装中还会有另一个文件。我建议:cd ~/Library/LaunchAgents/然后四处看看是否有mysql*。如果有,比如[[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection),然后删除它。
以下是一些对我有用的:

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"
(Note上面的括号和引号是为了防止grep出现在进程列表中并匹配自己,不像懒惰的版本:ps -ax | grep mysql,这将给给予印象,有一个额外的mysql进程正在运行)
一旦你准备好了,请运行:brew services list,仔细检查你没有mysql在里面。然后仔细检查你没有任何mysql进程在运行:
ps -ax | grep "[m]ysql"这可能会发生,例如,如果您输入mysqld例如.您可能需要执行brew services stop mysqlbrew services stop [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)或类似的操作,如果您在服务列表或进程列表中看到任何内容,请重复步骤。
最后,您应该准备好进行全新安装。全新安装过程应该相当简单:

brew install [email protected]
brew link --force [email protected]
brew services start [email protected]


然后运行brew services list以确保您的安装工作正常。如果您看到它是绿色和“已启动”,则您的安装成功!
您还应该运行:mysql_secure_installation然后选择root用户的密码并检查验证等问题列表。
安装完成后,你可能会遇到mysql模式的问题. cd /opt/homebrew/etc,你应该会找到一个我的.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 [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)
然后仔细检查您是否仍处于“已启动”的绿色状态:
brew services list
如果你这样做,那么你应该禁用no_zero_in_date模式。
你可以用一个查询来测试它:
SELECT @@sql_mode;
你现在应该有mysql 5.7运行在Apple Silicon上,并设置了sql_mode。
如果您遇到更多的故障排除,请尽最大努力进入已知状态,例如已安装,重新安装或已安装某些版本等。

von4xj4u

von4xj4u3#

我解决了这个问题后,几个小时的搜索,这是因为我没有清理一切关于我以前的MySQL 8.X安装。我跟着this,并得到怀疑,当我意识到我没有大部分的文件夹在那里。然后我做了一个搜索所有文件夹命名为mysql在我的计算机上,并发现一个mysql文件夹在opt/homebrew/var。删除后,重新安装MySQL 5.7,并启动服务器,一切都按预期工作。

vxf3dgd4

vxf3dgd44#

当设置我的苹果M1 MacBook Pro我遇到了以下错误消息被抛出的问题:

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

字符串
我的修正是修改MySQL配置文件:

nano /usr/local/etc/my.cnf


添加以下行:

tmpdir=/tmp
user=root


然后运行:

brew services restart [email protected]


这解决了我的问题,然后我就可以成功连接到我的DB客户端了。

pokxtpni

pokxtpni5#

看来我找到了解决方案(或变通办法)。
安装MySQL 5.7和Homebrew后,只需运行:

mysql.server start

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

yhived7q

yhived7q6#

我得到了这个警告:

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

字符串
我运行这两个命令,然后它工作。

相关问题