I installed MySQL via MacPorts. What is the command I need to stop the server (I need to test how my application behave when MySQL is dead)?
I installed MySQL via MacPorts. What is the command I need to stop the server (I need to test how my application behave when MySQL is dead)?
There are different cases depending on whether you installed MySQL with the official binary installer, using MacPorts, or using Homebrew:
brew services start mysql
brew services stop mysql
brew services restart mysql
sudo port load mysql57-server
sudo port unload mysql57-server
Note: this is persistent after a reboot.
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart
In my case, it kept on restarting as soon as I killed the process using PID. Also brew stop command didn't work as I installed without using homebrew. Then I went to mac system preferences and we have MySQL installed there. Just open it and stop the MySQL server and you're done. Here in the screenshot, you can find MySQL in bottom of system preferences. 
sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper stop
You can also use start and restart here. I found this by looking at the contents of /Library/LaunchDaemons/org.macports.mysql.plist.
Apparently you want:
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
Have a further read in Jeez People, Stop Fretting Over Installing RMagic.
Well, if all else fails, you could just take the ruthless approach and kill the process running MySQL manually.
That is,
ps -Af
to list all processes, then do "kill <pid>" where <pid> is the process id of the MySQL daemon (mysqld).
Get instance name:
ls /Library/LaunchDaemons | grep mysql
Stop MySQL instance (Works on MacOS Catalina, MySQL 8):
sudo launchctl unload /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
Or, you can Stop MySQL instance in
MacOS Settings > MySQL > Stop MySQL Server
Also, check here for more methods: https://tableplus.com/blog/2018/10/how-to-start-stop-restart-mysql-server.html
As @gediminas said
System Preferences > MySQL > Stop MySQL Server
Was the easiest way. With binary installer downloaded from Oracle.
For me the following solution worked Unable to stop MySQL on OS X 10.10
To stop the auto start I used:
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysql.plist
And to kill the service I used:
sudo pkill mysqld
If you installed the MySQL 5 package with MacPorts:
sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql.plist
Or
sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5-devel.plist
if you installed the mysql5-devel package.
After try all those command line, and it is not work.I have to do following stuff:
mv /usr/local/Cellar/mysql/5.7.16/bin/mysqld /usr/local/Cellar/mysql/5.7.16/bin/mysqld.bak
mysql.server stop
This way works, the mysqld process is gone. but the /var/log/system.log have a lot of rubbish:
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.
This worked for me on macOS 10.13.6 with 8.0.12 MySQL
/usr/local/mysql/support-files/mysql.server start
/usr/local/mysql/support-files/mysql.server restart
/usr/local/mysql/support-files/mysql.server stop