How do you stop MySQL on a Mac OS install?

MysqlMacos

Mysql Problem Overview


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)?

Mysql Solutions


Solution 1 - Mysql

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

Solution 2 - Mysql

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

Solution 3 - Mysql

You can always use command "mysqladmin shutdown"

Solution 4 - Mysql

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

Solution 5 - Mysql

sudo /usr/local/mysql/support-files/mysql.server stop

Solution 6 - Mysql

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. enter image description here

Solution 7 - Mysql

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.

Solution 8 - Mysql

Apparently you want:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop

Have a further read in Jeez People, Stop Fretting Over Installing RMagic.

Solution 9 - Mysql

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

Solution 10 - Mysql

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).

Solution 11 - Mysql

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

Solution 12 - Mysql

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

Solution 13 - Mysql

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).

Solution 14 - Mysql

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

Solution 15 - Mysql

As @gediminas said

System Preferences > MySQL > Stop MySQL Server

Was the easiest way. With binary installer downloaded from Oracle.

Solution 16 - Mysql

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

Solution 17 - Mysql

On OSX Snow Leopard

launchctl unload /System/Library/LaunchDaemons/org.mysql.mysqld.plist

Solution 18 - Mysql

For me the following solution worked https://stackoverflow.com/questions/29375253/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

Solution 19 - Mysql

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.

Solution 20 - Mysql

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.

Solution 21 - Mysql

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

Solution 22 - Mysql

mysql> show variables where variable_name like '%dir%';

| datadir | /opt/local/var/db/mysql5/ |

Solution 23 - Mysql

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLaurie YoungView Question on Stackoverflow
Solution 1 - MysqlmloughranView Answer on Stackoverflow
Solution 2 - MysqlpjammerView Answer on Stackoverflow
Solution 3 - MysqlRimantasView Answer on Stackoverflow
Solution 4 - MysqlJanView Answer on Stackoverflow
Solution 5 - MysqlMoesioView Answer on Stackoverflow
Solution 6 - MysqlAbhijeet KhangarotView Answer on Stackoverflow
Solution 7 - Mysqlkaty lavalleeView Answer on Stackoverflow
Solution 8 - MysqlDanView Answer on Stackoverflow
Solution 9 - MysqlzackView Answer on Stackoverflow
Solution 10 - MysqlSteveView Answer on Stackoverflow
Solution 11 - MysqlDuc ChiView Answer on Stackoverflow
Solution 12 - Mysqlppostma1View Answer on Stackoverflow
Solution 13 - MysqlJohn MontgomeryView Answer on Stackoverflow
Solution 14 - MysqlGediminasView Answer on Stackoverflow
Solution 15 - MysqlJaime BulaView Answer on Stackoverflow
Solution 16 - MysqlAllisoneView Answer on Stackoverflow
Solution 17 - MysqlsweetfaView Answer on Stackoverflow
Solution 18 - MysqlcodeaprendizView Answer on Stackoverflow
Solution 19 - MysqlBartosz BlimkeView Answer on Stackoverflow
Solution 20 - Mysqlbronze manView Answer on Stackoverflow
Solution 21 - MysqlManuel_BView Answer on Stackoverflow
Solution 22 - MysqlJack PengView Answer on Stackoverflow
Solution 23 - MysqlSzekelygobeView Answer on Stackoverflow