MacOSX: autostart mysql on boot

34,507

Solution 1

brew info mysql gives you the instructions for loading MySQL at startup, but here's all you need to do:

mkdir -p ~/Library/LaunchAgents
cp `brew --prefix mysql`/*mysql*.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/*mysql*.plist

Solution 2

Nowadays, brew info mysql gives you this statement:

To have launchd start mysql now and restart at login: brew services start mysql

Or, if you don't want/need a background service you can just run: mysql.server start

So running brew services start mysql will ensure it will run as a service and re-start on every login.

If you run that command with sudo:

sudo brew services start mysql

will make the service run on boot and not after logging in, which is more useful for servers.

Solution 3

Mipadi's answer failed for me with MySQL 5.6.13 installed with Homebrew on the date of this post. But I checked brew info mysql as he suggested and it gave me a working solution:

> ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

Solution 4

You don't need to setup a plist anymore. The latest version of brew (1.3.4) as of Oct 2017, you can only run:

brew services start <service_name>

and it will auto start every time you restart your computer. The command brew info gives you this

To have launchd start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: mysql.server start

Solution 5

Followup to Alejandro that couldn't fit in a comment.

Check which services are user (login) and root (boot) with this:

$ brew services list
Name       Status  User   Plist
chronograf started jacob  /Users/jacob/Library/LaunchAgents/homebrew.mxcl.chronograf.plist
grafana    started jacob  /Users/jacob/Library/LaunchAgents/homebrew.mxcl.grafana.plist
influxdb   started root   /Library/LaunchDaemons/homebrew.mxcl.influxdb.plist
kapacitor  stopped        
mariadb    started jacob  /Users/jacob/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
memcached  started jacob  /Users/jacob/Library/LaunchAgents/homebrew.mxcl.memcached.plist
telegraf   started jacob  /Users/jacob/Library/LaunchAgents/homebrew.mxcl.telegraf.plist
Share:
34,507

Related videos on Youtube

Tim Baas
Author by

Tim Baas

Self-made entrepreneur and programmer. Current projects: Packhouse ServiceBook Swapp Past projects: Buildion The Flying Dutchmen No Dutch No Glory Is it a Bird BaasCommandeur Heren Kaktus

Updated on July 09, 2022

Comments

  • Tim Baas
    Tim Baas almost 2 years

    I just installed mysql in terminal through homebrew.

    Now when I try to connect to mysql it fails, but after I run mysqld it works..

    So what I need to do now is run mysqld when I boot my Mac.

    I've searched Google for mysqld autoload at startup etc. but couldn't find the right answer.

    Hope someone can point me in the right direction.. Thanks!

  • joanwolk
    joanwolk almost 12 years
    I believe this is only true if you've installed mysql via brew, but it's great if you have!
  • mtkopone
    mtkopone over 11 years
    In my latest installation, the plist file is named: homebrew.mxcl.mysql.plist
  • chhantyal
    chhantyal over 9 years
    And if you have Mariadb installed, file name is : homebrew.mxcl.maraidb.plist
  • l008com
    l008com about 6 years
    This is the ONLY answer that actually answers the question, and launches the server at BOOT and not LOGIN. It creates the right .plist in the right location. This should really be marked as the right answer... even though it's not actually working for me. But I think that is a separate issues.
  • RonLugge
    RonLugge over 4 years
    While this answer is historically accurate, the more recent brew services start command is the modern solution, easier to work with than the arcane launchctl
  • gone
    gone almost 4 years
    Should this go in /Library/LaunchAgents or /Library/LaunchDaemons? I think the later.
  • Oleksii Nezhyborets
    Oleksii Nezhyborets over 2 years
    Won't allow to do sudo because "Running Homebrew as root is extremely dangerous and no longer supported". How do I do it on boot now?
  • Alejandro Iván
    Alejandro Iván over 2 years
    Looks like there's no way unless root owns the brew executable. You'll probably need to go the LaunchDaemons way from other answers. IMHO this is the worst decision people from Homebrew has made. We know what we're doing, there should at least be a toggle do disable that stupid enforcement.