How to Start & Stop MySQL Manually in OS X El Capitan & Yosemite

Nov 26, 2014 - 9 Comments

Terminal in OS X Many developers require MySQL on their Macs, but if you’ve tried to install MySQL in OS X El Capitan and Yosemite, you likely noticed that you’ll get an “installation failed” error during the process. That error sounds worse than it is, because you can avoid it entirely by choosing not to install the startup item included in the MySQL bundle, or, you can just ignore the installation error and start MySQL yourself when you need it. Either way, MySQL actually installs fine, it’s just the bundled startup item that does not function. As you probably guessed, that means you’ll need to start and stop MySQL yourself.


Yes a preference panel gets installed that allows for a GUI approach, but many users prefer to use the command line for this purpose since many of us work in the Terminal anyway, and it has the added possibility of being automated.

Starting, Stopping, Restarting MySQL on Mac OS X

Hre are the three basic commands to start, stop, and restart MySQL in Mac OS X, including OS X El Capitan and OS X Yosemite. Be sure to enter the command onto a single line, sudo obviously requires an administrator password to be entered.

Start MySQL

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

Stop MySQL

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

Restart MySQL

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

Of course, these can be combined with starting and stopping Apache server if your intention is to setup a local web development environment.

You can download the latest version of MySQL for Mac OS X here. Future versions of the MySQL installer will undoubtedly fix this for OS X but in the meantime if you get the installation error, either customize the installer and avoid the startup item, or ignore the error and start and stop mysql yourself when it’s needed.

Those interested can also follow a workaround posted to StackOverflow here to automatically load MySQL on boot in OS X El Capitan or Yosemite.

Start, Stop, Restart MySQL from Mac OS Preference Panel

Of course, you can also start and stop the MySQL server from the bundled preference panel. To do that, simply go to the  Apple menu and open System Preferences. Choose the “MySQL” preference panel, then click on the “Start MySQL Server” button to start MySQL Server on Mac. If the server is already started, the button will change to “Stop MySQL Server”. If you want to restart the server, simply click to turn it off, wait a minute or so, then turn it back on again. This will be the easy approach for many Mac users, though you’ll have to fiddle with the pref panel as necessary, and if you go that route you’ll want to uncheck the auto-start option because it’s going to fail.

MySQL Start and Stop server in Mac OS X

I’m partial to the command line approach for the time being, but use whatever is most appropriate for your situation.

By the way, these mySQL server management methods continue to work in MacOS Sierra as well.

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

9 Comments

» Comments RSS Feed

  1. kerednai says:

    It seems that I can start / stop from the command line as per the article & it will show the status in system preferences. If you start using system preferences however you cannot stop using the command line. At least that is what I have observed so far.

  2. mycaravam says:

    1.) Kill all db processes
    sudo killall mysqld
    2.) Restart
    sudo brew services restart mysql

  3. Digimix says:

    It also depends on where MySQL is installed on your operating system.

    For example, this is the command to start and stop if you are on OS X Sierra and installed MySQL from official MySQL package:

    $ /usr/local/bin/mysql.server start

    • Tuan Anh says:

      I don’t think so.
      I’m using 10.12.5 and MySQL installed by official package but I’m still able to use commands in this article. And I also have problem like Peterson.

    • Taylor says:

      Thank you, I tried everything and this finally worked for me. Especially when dealing with the ‘ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)’ error

  4. Pavel says:

    Thank you for the information!

  5. David White says:

    Jefferis, I had the same problem. But I think it probably stopped MySQL anyway, because when I did the same but with a restart command, I got the PID error, and then mysql restarted…

    $ sudo /usr/local/mysql/support-files/mysql.server restart
    ERROR! MySQL server PID file could not be found!
    Starting MySQL
    .. SUCCESS!

    So just do the command as it says above, then proceed. But I got another error:

    $ sudo mysqld_safe –skip-grant-tables
    sudo: mysqld_safe: command not found

    “mysqld_safe” command was not found. So modify the syntax a bit, and then proceed as usual:

    sudo /usr/local/mysql/support-files/mysql.server start –skip-grant-tables
    Starting MySQL
    .. SUCCESS!
    $ mysql -u root

    –> you’re in! Thanks for the tutorial.

  6. I cannot get the server to shut down. I get this error in command line: ERROR! MySQL server PID file could not be found!
    And the Control Panel Sys pref button will not work.
    Help!

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site