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


当前回答

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

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.

其他回答

你可以使用命令"mysqladmin shutdown"

如果你正在使用自制啤酒,你可以使用

brew services restart mysql
brew services start mysql
brew services stop mysql

获取可用服务的列表

brew services list

在我的例子中,只要我使用PID杀死进程,它就会重新启动。此外,brew stop命令不工作,因为我没有使用自制程序安装。然后我打开了mac系统首选项,那里已经安装了MySQL。只要打开它并停止MySQL服务器,你就完成了。在这里的截图中,你可以在系统首选项的底部找到MySQL。

我在macports上安装了mysql5和mysql55。对我来说,这里提到的文件位于以下位置:

(mysql55-server) / opt /地方/ etc / LaunchDaemons / org.macports.mysql55-server / org.macports.mysql55-server.plist

(mysql5) / opt / local / etc / LaunchDaemons - org . macports mysql5 mysql5 - org . macports。plist

所以停下来是这样做的:

mysql55-server:

sudo launchctl unload -w /opt/local/etc/LaunchDaemons/org.macports.mysql55-server/org.macports.mysql55-server.plist

mysql5:

sudo launchctl unload -w /opt/local/etc/LaunchDaemons/org.macports.mysql5/org.macports.mysql5.plist 

您可以检查服务是否仍在运行:

ps ax | grep mysql

此外,你可以在我的案例中查看日志文件:

mysql55-server

sudo tail -n 100 /opt/local/var/db/mysql55/<MyName>-MacBook-Pro.local.err
...
130213 08:56:41 mysqld_safe mysqld from pid file /opt/local/var/db/mysql55/<MyName>-MacBook-Pro.local.pid ended

mysql5:

sudo tail -n 100 /opt/local/var/db/mysql5/<MyName>-MacBook-Pro.local.err
...
130213 09:23:57  mysqld ended

获取实例名:

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