16

Just installed MariaDB (with homebrew). Everything looks like it's working, but I can't figure out how to have it automatically startup on boot on my Mac. I can't find any Mac-specific docs for this.

The installation output says:

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

I guess I don't know where the right place is.

Grant Birchmeier
  • 17,809
  • 11
  • 63
  • 98
  • What are the contents of `mysql.server`? Does it look like a script, or is it an XML plist? – prodigitalson Jul 04 '13 at 02:59
  • It's a shell script. On linux, I'd expect to put this in the rc dirs or something. Not sure what the OS X way is (I've been spoiled by fancy packagers). – Grant Birchmeier Jul 04 '13 at 03:10
  • 1
    The accepted answer below will launch MariaDB on user login, but it will not launch it on boot. I'm still trying to find an on-boot solution myself. Putting the login script in /Library/LaunchDaemons doesn't seem to work. – l008com Mar 17 '18 at 07:06

4 Answers4

19

From brew info mariadb

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

Just run brew services start mariadb on terminal.

Sucipto
  • 817
  • 1
  • 8
  • 19
  • That may not have been there when I originally posted the question. – Grant Birchmeier Aug 26 '16 at 14:29
  • 1
    @GrantBirchmeier Maybe useful for someone searching the same question in the future :D – Sucipto Aug 26 '16 at 14:51
  • returns `Service mariadb already started, use brew services restart mariadb to restart.` on mine, neither `start` or `restart` work. there's no process showing for it. The only consistent way I have is to reinstall `brew upgrade mariadb` it after every reboot! – frumbert Aug 07 '19 at 08:25
10

With help from Calvin's answer (deleted, I guess?), and this page, these are the steps I used to accomplish this:

cp /usr/local/Cellar/mariadb/5.5.30/homebrew.mxcl.mariadb.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

On next boot, MariaDB was up and running.

Grant Birchmeier
  • 17,809
  • 11
  • 63
  • 98
  • 1
    ~/Library/LaunchAgents starts the server on login, not on boot. If you disable automatic login on your machine, the database will not be running. Simply moving the plist from LaunchAgents to /Library/LaunchDeamons does not work. Which brings me back to the original question, can you start `mariadb` on *boot*? – l008com Mar 17 '18 at 07:04
  • Ha, you're absolutely right, and now I realize that I actually meant to say "on login" in the first place! Luckily, I only needed this for dev, and not production. – Grant Birchmeier Mar 19 '18 at 14:31
9

If you install MariaDB by Homebrew, you can use this to see how to start your mariadb at login.

brew info mariadb

To have launchd start mariadb at login:

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

Then to load mariadb now:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

Or, if you don't want/need launchctl, you can just run:

mysql.server start
WalkerAI
  • 91
  • 1
  • 3
2

You need to use launchd. See $ man launchd.

Additionally, Nathan wrote a good article on launchd.

Seyeong Jeong
  • 10,658
  • 2
  • 28
  • 39