This is a quick post as much to remind myself the next time I need it as anything about how to start and stop MySQL from a terminal window on OS X. When you install MySQL it defaults to auto starting at login. I like to have control over when the services that I use for development are started and stopped–hence I start Apache 2, ColdFusion and PostFIx from a terminal window when I’m getting ready to work. Until today, I had just lived with the fact that MySQL started automatically when you logged in. I finally got off my lazy butt and decided to do some searching on the command-line syntax to start and stop MySQL.
As is generally my luck, it’s taking me longer to write this post than it did to find the answer in the “new evil empire” (that’s Google for those of you like me that haven’t joined the anti-Google bandwagon yet). The commands are pretty straightforward but it’s still nice to set up an alias in your terminal profile so you don’t have to remember them. They are:
Start:
sudo /usr/local/mysql/support-files/mysql.server start
Stop:
sudo /usr/local/mysql/support-files/mysql.server stop
I set an alias for each of those in my .bash_profile so I only have to type mysql-start
and mysql-stop
respectively. The only other thing you’ll want to do is remove the startup item from /Library/StartupItems
with the following command:
sudo rm -rf /Library/StartupItems/MySQLCOM/
Many thanks to this blog post on the “explorer’s club” blog (specifically steps 3.3 and 4.3) for getting me on the right track.