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)?
24 Answers
There are different cases depending on whether you installed MySQL with the official binary installer, using MacPorts, or using Homebrew:
Homebrew
brew services start mysql
brew services stop mysql
brew services restart mysql
MacPorts
sudo port load mysql57-server
sudo port unload mysql57-server
Note: this is persistent after a reboot.
Binary installer
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart

- 11,415
- 7
- 28
- 22
-
1Thanks a ton - I had the stop and start commands, but didn't know about/think about trying restart. After using the stop command, start would do nothing, as would starting from the MySQL System Preferences panel. – Ross Henderson Apr 16 '11 at 01:00
-
4In my case it was slightly different, because the mysql version number was added in the plist file. It was like that: sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5.plist sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist – d1rk Oct 26 '11 at 10:23
-
1And for me, /opt/local/etc/LaunchDaemons/org.macports.mysql5/org.macports.mysql5.plist – Dmitry Minkovsky Jun 30 '12 at 21:00
-
11And for homebrew: `launchctl (un)load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist` – Kostas Jun 12 '13 at 12:48
-
@vrinek Tahnk you - That did it for me - Except the file is `~/Library/LaunchAgents/com.mysql.mysqld.plist` – troelskn Aug 01 '13 at 10:02
-
Why not just `sudo mysql.server stop` etc.? Any proper installation, regardless of method, should have put that in your PATH. I've installed through Homebrew and mentioned short form works fine. – Markus Amalthea Magnuson Jun 03 '14 at 13:18
-
2If you have [Homebrew Services](https://github.com/Homebrew/homebrew-services) installed, you can use `brew services stop mysql` and `brew services start mysql`. (Also `restart`, and `run` which starts for the current session only.) – medmunds May 27 '17 at 18:14
-
@MarkusAmaltheaMagnuson I get `.. ERROR! The server quit without updating PID file (/usr/local/var/mysql/TRSS-MacBook-Pro.local.pid).` but not with the `launchctl` or `brew services` approach. – trss Jul 26 '17 at 13:30
-
Didn't work for me. Kept getting this error: /Users/charlie/Library/LaunchAgents/homebrew.mxcl.mysql.plist: No such file or directory – 2myCharlie Aug 01 '18 at 20:14
-
This worked for me ```sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist``` – Winnipass Aug 27 '19 at 01:38
For those who used homebrew to install MySQL use the following commands below to start, stop, or restart MySQL
Brew start
/usr/local/bin/mysql.server start
Brew restart
/usr/local/bin/mysql.server restart
Brew stop
/usr/local/bin/mysql.server stop

- 9,489
- 5
- 46
- 56
-
5For me, the install directory by homebrew is `/usr/local/Cellar/mysql@5.7/5.7.23/bin/` – Moobie Jan 29 '19 at 08:45
You can always use command "mysqladmin shutdown"

- 1,471
- 9
- 6
-
1The commands above didn't work for me. This one did. Not sure what the difference is in my setup, but thanks. – Marco Sep 06 '09 at 01:10
-
2Even though it may work, if you're using MacPorts and run this, launchctl will not realize mysql has stopped and will complain if you try to start it (load). Using launchctl is thus preferable. – lambshaanxy Jul 06 '11 at 02:22
-
1Also although this works for shutting down the server, it won't do anything to help you bring it back up when you want to restart it. – aroth Aug 09 '11 at 01:59
-
4Remember to add -p and enter your mysql root password when prompted. At my setup where mysql is installed with MacPorts mysql restarted, and reloaded the config, which was the target for my action. – Jesper Grann Laursen Nov 26 '13 at 20:58
-
1`sudo /opt/local/lib/mysql56/bin/mysqladmin shutdown` if your mysql comes from MacPorts – Alain Tiemblo Nov 28 '14 at 20:12
-
Works fine for homebrew installed mysql. I had to execute the command as sudo (i.e. `sudo mysqladmin shutdown`) – Staccato Sep 14 '15 at 06:15
-
This is the only one that worked for me. I just needed to add `sudo` to the beginning. – Nick Manning Mar 06 '16 at 22:02
-
I got this error for the above command: mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'lorcz'@'localhost' (using password: NO)' – 2myCharlie Aug 01 '18 at 20:15
If you are using homebrew
you can use
brew services restart mysql
brew services start mysql
brew services stop mysql
for a list of available services
brew services list

- 12,992
- 9
- 53
- 89
-
3This worked for me, even after interacting with launchctl directly did not. Thank you! – Lyndsy Simon Dec 14 '16 at 23:41
-
-
1This worked but I have to specify MySQL version with it. brew services restart mysql@5.7 – Abrar Ahmad Nov 12 '21 at 05:27
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.

- 1,281
- 1
- 16
- 25
-
2Worked for direct install through .pkg, version 8.0.27-arm64 on Big Sur. – SagarM Nov 20 '21 at 06:08
sudo /usr/local/mysql/support-files/mysql.server stop

- 3,100
- 1
- 27
- 36
-
3+1 this was only one that worked for me---I just used the DMG installer from Mysql. Thanks – Dolan Antenucci Feb 09 '13 at 15:20
-
1for me its giving this error. `$ sudo /usr/local/mysql/support-files/mysql.server stop ERROR! MySQL server PID file could not be found! ` – codeaprendiz Jan 07 '21 at 12:45
-
1
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.

- 2,741
- 1
- 28
- 26
-
1This is how you're supposed to do it.. For MacPorts.. The `launchctl` method does NOT work, and in fact can cause problems with PID / DB startup bitching and moaning. – Alex Gray Mar 13 '12 at 04:01
Apparently you want:
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
Have a further read in Jeez People, Stop Fretting Over Installing RMagic.

- 30,738
- 21
- 105
- 131

- 61,568
- 9
- 61
- 78
Use:
sudo mysqladmin shutdown --user=*user* --password=*password*
One could probably get away with not using sudo. The user could be root for example (that is, the MySQL root user).

- 30,738
- 21
- 105
- 131

- 696
- 7
- 15
Try
sudo <path to mysql>/support-files/mysql.server start
sudo <path to mysql>/support-files/mysql.server stop
Else try:
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop<br>
sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart
However, I found that the second option only worked (OS X 10.6, MySQL 5.1.50) if the .plist has been loaded with:
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
PS: I also found that I needed to unload the .plist to get an unrelated install of MAMP-MySQL to start / stop correctly. After running running this, MAMP-MySQL starts just fine:
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist

- 3,198
- 2
- 35
- 51
On my mac osx yosemite 10.10. This command worked:
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysql.plist
You can find your mysql file in folder /Library/LaunchDaemons/ to run

- 391
- 4
- 8
-
2This is only way that worked for me. For any other methods, the `mysqld` process restarts immediately after stopped. – Rockallite Jun 07 '16 at 01:01
-
This is the only way which worked for me too. I switched from homebrew to the MySQL-supplied DMG and I think possibly the brew version was still running even though I uninstalled it. – Sam Critchley Jan 18 '17 at 09:43
Latest OSX (10.8) and mysql 5.6, the file is under Launch Daemons and is com.oracle.oss.mysql.mysqld.plist. It presents an option under System Options, usually the bottom of the list. So go to system settings, click on Mysql, and turn it off from the option box. https://dev.mysql.com/doc/refman/5.6/en/osx-installation-launchd.html

- 3,616
- 1
- 27
- 28
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

- 7,101
- 7
- 46
- 59
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).

- 56,435
- 29
- 168
- 265

- 8,868
- 4
- 33
- 43
-
yeah.. this one is the best and universal for scripting. Do you think there is possibility of data corruption? or any other problems? – user425720 Nov 11 '10 at 19:01
-
1
-
As @gediminas said
System Preferences > MySQL > Stop MySQL Server
Was the easiest way. With binary installer downloaded from Oracle.

- 51
- 3
On OSX Snow Leopard
launchctl unload /System/Library/LaunchDaemons/org.mysql.mysqld.plist

- 5,457
- 2
- 48
- 62
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

- 2,703
- 1
- 25
- 49
For me it's working with a "mysql5"
sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

- 8,434
- 4
- 32
- 54
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.

- 30,738
- 21
- 105
- 131

- 6,498
- 3
- 24
- 19
-
1This will stop it from starting when you reboot, which is not what the poster was asking for. – Matthew Schinckel Sep 19 '08 at 10:27
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.

- 1,470
- 2
- 15
- 28
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

- 2,309
- 1
- 19
- 25
I installed mysql5 and mysql55 over macports. For me the mentioned files here are located at the following places:
(mysql55-server) /opt/local/etc/LaunchDaemons/org.macports.mysql55-server/org.macports.mysql55-server.plist
(mysql5) /opt/local/etc/LaunchDaemons/org.macports.mysql5/org.macports.mysql5.plist
So stopping for these works like this:
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
You can check if the service is still running with:
ps ax | grep mysql
Further you can check the log files in my case here:
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

- 535
- 5
- 10
mysql> show variables where variable_name like '%dir%';
| datadir | /opt/local/var/db/mysql5/ |

- 576
- 5
- 19