[英]How to install and start MySQL 5.7 on macOS BigSur (Apple Silicon) with Homebrew?
我需要使用 M1 将特定版本的 MySQL (5.7) 安装在我的 MacBook 上。
我正在尝试使用 Homebrew 来做到这一点。
brew install mysql@5.7
output:
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
似乎存在与权限相关的问题。 任何建议表示赞赏。
经过几个小时的搜索,我解决了这个问题,这是因为我没有清理我之前安装的 MySQL 8.X 的所有内容。 当我意识到我那里没有大部分文件夹时,我跟着这个并开始怀疑。 然后,我在计算机上搜索了所有名为mysql
的文件夹,并在opt/homebrew/var
中找到了mysql
文件夹。 删除它后,重新安装 MySQL 5.7,并启动服务器,一切都按预期工作。
好像我找到了解决方案(或解决方法)。
使用 Homebrew 安装 MySQL 5.7 后,只需运行:
mysql.server start
MySQL 已启动,然后您可以运行mysql_secure_installation
和mysql
命令。
我收到了这个警告:
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
我运行这两个命令然后它工作。
在设置我的 Apple M1 Macbook Pro 时,我遇到了以下错误消息的问题:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
我的修复是修改 MySQL 配置文件:
nano /usr/local/etc/my.cnf
Append 以下几行:
tmpdir=/tmp
user=root
然后运行:
brew services restart mysql@5.7
这解决了我的问题,然后我能够成功连接到我的数据库客户端。
如果您遇到“ Can't connect to local MySQL server through socket '/tmp/mysql.sock'
”或“ The post-install step did not complete successfully MySQL
”等问题,并且您安装了以前版本的 Z81C3B080DAD537BF5EZA4E (例如 8.x) 以前,您可能需要在重新安装首选版本的 mysql@xx 之前清理所有内容
如果您已经访问过这些链接: 卸载所有损坏的 MySQL 版本并在 Mac Mavericks (Coderwall) 上使用 Brew 重新安装+ 在 macOS 上使用 Homebrew (github) 安装 MySQL 5.7并且您仍然无法启动您的 mysql 服务,您也应该尝试删除/opt/homebrew/etc/my.cnf
文件。
也将其与所有相关文件一起删除! M1 Apple Silcion 机器总结,通过brew uninstall mysql
或brew uninstall mysql@xx
后,请删除:
/opt/homebrew/var/mysql
/opt/homebrew/etc/my.cnf
在此之后,一切都像全新安装一样(对我而言)。 希望这节省了某人的时间。
虽然这个问题特定于 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 文件并使其难以使用并混淆自制软件。
我遇到了这些指南:
在 macOS 上冲泡安装 mysql
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"
(Note the brackets and quotes in the above is to prevent the grep from showing up in the process list and matching itself unlike the lazier version: ps -ax | grep mysql
which will give the impression there's an extra mysql process running)
准备好后,请运行: mysql services list
仔细检查您那里没有 mysql。 然后仔细检查您没有运行任何 mysql 进程:
ps -ax | grep "[m]ysql"
ps -ax | grep "[m]ysql"
例如,如果您输入mysqld
,则可能会发生这种情况...。您可能需要执行 mysql services stop mysql
或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 和 go 选择密码。
安装后,您可能还会遇到 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。
如果您遇到更多故障排除,请尽力进入已知状态,例如已卸载、重新安装或已安装某些版本等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.