mac 安装 卸载mysql
Homebrew 国内安装脚本,快速部署 brew ,国内镜像
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
brew remove mysql@5.7 一定要有版本
brew install mysql@8.4
brew remove mysql
报错
Error: No such keg: /opt/homebrew/Cellar/mysql
查看
brew info mysql
取消链接
brew unlink mysql
强制卸载
brew uninstall --ignore-dependencies mysql
brew cleanup mysql
手动删除
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /opt/homebrew/var/mysql
sudo rm -rf /usr/local/etc/my.cnf
sudo rm -rf /opt/homebrew/etc/my.cnf
检查启动代理
launchctl list | grep mysql
如果有则删除
launchctl remove homebrew.mxcl.mysql
重新安装 MySQL
如果不加版本号,会安装最新版 9.3
brew install mysql
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api/formul ==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api/cask.j ==> Fetching mysql ==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/mysql-9.3. Already downloaded: /Users/daiaihua/Library/Caches/Homebrew/downloads/b0e3f52c62182b06a1bb6228c465c6df1f44e7f453000441588bb063af4dae22--mysql-9.3.0.arm64_sequoia.bottle.tar.gz ==> Pouring mysql-9.3.0.arm64_sequoia.bottle.tar.gz ==> /opt/homebrew/Cellar/mysql/9.3.0/bin/mysqld --initialize-insecure --user=dai ==> Caveats Upgrading from MySQL <8.4 to MySQL >9.0 requires running MySQL 8.4 first: - brew services stop mysql - brew install mysql@8.4 - brew services start mysql@8.4 - brew services stop mysql@8.4 - brew services start mysql 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 -u root To start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/mysql/bin/mysqld_safe --datadir\=/opt/homebrew/var/mysql ==> Summary 🍺 /opt/homebrew/Cellar/mysql/9.3.0: 333 files, 291.9MB ==> Running `brew cleanup mysql`... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
指定数据库目录运行
/bin/sh /opt/homebrew/Cellar/mysql/9.3.0/bin/mysqld_safe --datadir=/Volumes/SSD4T/mysql_data
启动服务
brew services start mysql
初始化配置(登录密码):
mysql_secure_installation
报错:
Error: Failure while executing; `/bin/launchctl bootstrap gui/501
查看/Users/daiaihua/Library/LaunchAgents/homebrew.mxcl.mysql.plist
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <true/> <key>Label</key> <string>homebrew.mxcl.mysql</string> <key>LimitLoadToSessionType</key> <array> <string>Aqua</string> <string>Background</string> <string>LoginWindow</string> <string>StandardIO</string> <string>System</string> </array> <key>ProgramArguments</key> <array> <string>/opt/homebrew/opt/mysql/bin/mysqld_safe</string> <string>--datadir=/opt/homebrew/var/mysql</string> </array> <key>RunAtLoad</key> <true/> <key>WorkingDirectory</key> <string>/opt/homebrew/var/mysql</string> </dict> </plist>
在命令行直接运行:
/opt/homebrew/opt/mysql/bin/mysqld_safe
然后会提示错误文件地址:
2025-05-19T07:06:46.6NZ mysqld_safe Logging to '/opt/homebrew/var/mysql/192.168.124.15.err'.
查看错误日志,发现以下报错:
Plugin mysqlx reported: 'Setup of socket: '/tmp/mysqlx.sock' failed, can't open lock file /tmp/mysqlx.sock
解决方案: 直接删除/tmp下的mysql*.lock,然后重启
默认配置文件
opt/homebrew/opt/mysql/homebrew.mxcl.mysql.plist
启动脚本
mysql.server start
浙公网安备 33010602011771号