How can I disable MySQL from starting at boot?

I have a mid 2013 MBA running OSX 10.9.

The process that starts on every start up is mysqld. I believe it was from an old version of MySQL I had installed (via AMPPS). I then installed MAMP Pro and I often have conflicts between these two processes. Everytime I shut down and restart my mac, I have to find the process of mysqld that is running (on activity monitor), quit it, and then start MAMP (via the terminal command: /Application/MAMP/bin/startMysql.sh won't work from anywhere else).

So I'm wondering how I can disable this mysqld from running on every startup.


Solution 1:

Open terminal, then:

sudo launchctl list | grep -i mysql

launchctl remove xxx.xxx.mysql

Where "xxx.xxx" is included in the output of the first command, for example "org.macports.mysql". The password for the "sudo" command is your own user account's password.

True, sudo isn't needed to "list" but because you already gave a sudo password for the first command, it is stored for a short while in session memory and isn't required for the second command (which is privileged). Otherwise, just skip sudo on the first command and use it on the second. There are more ways than one to skin a cat.

Solution 2:

If the version of MySQL that was previously installed originated from the MySQL Community Downloads page on the SUN/Oracle site, it's likely that launchd is not involved with startup of the mysqld process. For some reason, the startup script that is distributed with MySQL uses the deprecated "Startup items" technology to start processes at boot. In fact, even the current binary distribution (5.6.15) of mysqld uses StartupItems to start the server on OS X(?!)

The startup script that's launching the conflicting version of MySQL is most likely located at /Library/StartupItems/MYSQLCOM/MYSQLCOM. At boot time, that startup item will examine the file at /etc/hostconfig to determine if the setting for the "MYSQLCOM" variable is set to "-YES-". If so, the startup script will launch mysqld.

It should be possible to disable the startup of MySQL by modifying the line in /etc/hostconfig that specifies MYSQLCOM=-YES- to say MYSQLCOM=-NO- (which should disable the startup process on the next boot).

You can terminate the currently running instance of mysqld by performing the command:

sudo /Library/StartupItems/MYSQLCOM/MYSQLCOM stop

To permanently disable the startup of the wrong mysqld process, it should be possible to first stop the daemon using the command above, and then to remove the MySQL startup item using the following command:

sudo rm -rf /Library/StartupItems/MYSQLCOM

Note: you may also have the MySQL Preference Pane installed at /Library/PreferencePanes/MySQL.prefpane or ~/Library/PreferencePanes/MySQL.prefpane...That preference pane can also be removed to 'cleanup' pieces of the old MySQL installation.

Solution 3:

The following worked for me with mysql 8.0.12 installed using Homebrew in macOS Mojave 10.14.1:

rm -rf ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Solution 4:

It might be easier to rename the mysqld (or move / back up / delete it) and then restart and look for the error message for the launch item that was trying to start the program that is no longer available.

The other answers seem to cover the tack of looking for Launch Agents and Launch Daemons as well as tracing the PID which generally doesn't work for daemons since they usually have a parent PID of 1.

Also, since mysql isn't shipped with Mavericks, you should be able to track the install package you selected or use mdfind mysqld to locate the package that brought that database to your Mac and then locate the uninstall / disable instructions for that package of mysql. You'll also want to look in system preferences in case you have installed a control there to start the software.

Solution 5:

Start off by finding out what the parent process is that started your mysql. From the Terminal run a ps command to find out what the process is; you can use -j or -l to list out the parent id ppid. So this will show you:

$ ps -axjc | grep mysql

The first column is your userid, the second is the process id, the third is the parent id.

If the parent id is 1 then it will have been launched by the root launch daemon, which probably means it's coming from one of the LaunchDaemons or StartupItems. If it comes from a process that isn't 1 but that is a launchd process then that's probably the LaunchAgents or is in your system login items.

root                1     0     1      0    0 Ss     ??    4:49.10 launchd
alblue            257     1   257      0    0 Ss     ??    0:16.29 launchd
_spotlight        415     1   415      0    0 Ss     ??    0:00.94 launchd

So process 1 is launched by system startup, and anything with the parent process of 1 comes from the system daemons. Anything (in this case) with a parent process of 257 is being launched from one of the LaunchAgents or LoginItems.

Bear in mind that the name of the launch daemon or startup item doesn't necessarily have 'mysql' in the title - it could have been run by a different program or login item (so simply searching for it by name might not find it). Once you've found what has launched it, you may be able to find out where it came from.