问题
I'm running OS X 10.11 El Capitan with its built-in server stack (Apache 2.4.16, MySQL 5.6.26).
I need to quit mysql, but killing the process immediately restarts it.
Here's what I've tried so far:
Killing the process
$ ps aux | grep mysql
to get the PID returns
74 49484 1 0 10:23AM ?? 0:00.46 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid --port=3307
Then, $ sudo kill -9 49484
kills the process, but it immediately restarts with with a higher PID.
Unloading mysqld from launchd
$ launchctl list | grep mysql
returns nothing, so there is nothing to $ launchctl unload
Stopping the mysql server
$ /usr/local/mysql/support-files/mysql.server stop
fails with "ERROR! MySQL server PID file could not be found!" despite the fact that mysql is running and the PID file is up-to-date in /usr/local/mysql/data/mysqld.local.pid.
The above are all suggested solutions I found on Stack Overflow, none of which work for me on El Capitan. On Yosemite, simply killing the process was sufficient but with the El Capitan update, mysql is immediately restarted.
Thanks.
回答1:
What finally worked for me was stopping MySQL through the Mac System Preferences interface. That killed mysql without it coming back.
回答2:
On macOS Sierra
, this worked for me
Stop MySQL:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Start MySQL:
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
回答3:
On OS X El Capitan, this worked for me:
sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
回答4:
I found that the following commands worked for me:
To Stop mysql:
sudo launchctl unload -F /Library/LaunchDaemons/com.mysql.mysql.plist
To Start mysql:
sudo launchctl load -F /Library/LaunchDaemons/com.mysql.mysql.plist
回答5:
If you used homebrew to install mysql, mysqld
will keep on restarting unless you use following brew command:
brew services list
Get the name of service to stop and then run the following command:
brew services stop mysql@5.5
回答6:
On my config I found this:
$ cat /Library/LaunchDaemons/com.mysql.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>com.mysql.mysqld</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/mysql/bin/mysqld_safe</string>
<string>--user=mysql</string>
</array>
</dict>
</plist>
You need to: change that true tag after KeepAlive to false and unload the daemon as others have suggested.
In my case that was:
sudo launchctl unload -F /Library/LaunchDaemons/com.mysql.mysql.plist && launchctl load /Library/LaunchDaemons/com.mysql.mysql.plist
Once the daemon will have restarted with the new config it will not keep mysql from being shut down when you kill it from the preferences.
回答7:
As per Theory's answer, this is still effective for Mojave
.
sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
Per amacrobert, if you are facing this issue of mysqld
continuing starting up, this is most likely due to you having mysql
installed on the system level and by default, it will startup automatically on a computer restart.
In my situation, I was confused after a computer restart why my docker
mysql
container complained about an already allocated port. After continual debugging, I remember I installed mysql
on the system level and never restarted my computer!
Cheer.
回答8:
this stopped mysql for me on Mac Sierra
sudo launchctl unload -F /Library/LaunchDaemons/homebrew.mxcl.mysql@5.7.plist
来源:https://stackoverflow.com/questions/32909740/quit-mysql-without-it-restarting-on-el-capitan