我通过MacPorts安装MySQL。我需要什么命令来停止服务器(我需要测试当MySQL死时我的应用程序如何行为)?


当前回答

获取实例名:

ls /Library/LaunchDaemons | grep mysql

停止MySQL实例(适用于MacOS Catalina, MySQL 8):

sudo launchctl unload /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

或者,您可以停止MySQL实例

MacOS Settings > MySQL > Stop MySQL Server 

此外,查看这里更多的方法: https://tableplus.com/blog/2018/10/how-to-start-stop-restart-mysql-server.html

其他回答

对于Mac M1 Pro,进入系统设置和Mysql在底部,然后点击停止Mysql服务器:

在我的mac osx yosemite 10.10。这个命令起作用了:

sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysql.plist

你可以在/Library/LaunchDaemons/文件夹中找到你的mysql文件来运行

这适用于macOS 10.13.6和8.0.12 MySQL

/usr/local/mysql/support-files / mysql。服务器启动

/usr/local/mysql/support-files / mysql。服务器重启

/usr/local/mysql/support-files / mysql。服务器停止

对我来说,它与mysql5一起工作

sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

尝试了所有的命令行,还是不行。我要做的事情有:

mv /usr/local/Cellar/mysql/5.7.16/bin/mysqld /usr/local/Cellar/mysql/5.7.16/bin/mysqld.bak
mysql.server stop

这种方法有效,mysqld进程消失了。但是/var/log/system.log有很多垃圾:

Jul  9 14:10:54 xxx com.apple.xpc.launchd[1] (homebrew.mxcl.mysql[78049]): Service exited with abnormal code: 1
Jul  9 14:10:54 xxx com.apple.xpc.launchd[1] (homebrew.mxcl.mysql): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.