Starting up MySQL on mac on boot

Discussion in 'macOS' started by estorstenson, Jun 7, 2013.

  1. estorstenson macrumors member

    Jan 30, 2013
    I have a mac mini with MySQL installed. The database is owned by my account (yeah, that is dumb, I know now...;) and if the machine is ever rebooted either to install updates or maybe the machine loses power, I have to manually launch mySQL using launchctl.

    I've tried adding entries to /Library/LaunchAgents based on the example provided by homebrew, but it always seems to fail. I did add in the key/value pair for UserName, but that doesn't seem to work.

    Any suggestions what I have done wrong?
  2. subsonix macrumors 68040

    Feb 2, 2008
    If this is only necessary on reboot you could perhaps try start up items.
  3. estorstenson thread starter macrumors member

    Jan 30, 2013
    Yeah, this won't work for my purposes: "Once set up, a "login item" is one that opens automatically after you log into the computer. " I want to avoid having to log in for the service to start. It should happen after the computer has rebooted.

    I have created an entry in /Library/LaunchAgents/homebrew.mxcl.mysql.plist, but it isn't working, either because it doesn't do what I want, or it can't run things as other users (even though you can associate a user account with it).
  4. subsonix macrumors 68040

    Feb 2, 2008
    Well, if you do not have a login, you will automatically be logged in. If you do have a login, your database will not start any way since you will be stuck at your login screen on reboot.

    One benefit of using launchd though, is that you can set additional properties like KeepAlive, which will restart your database if it should quit unexpectedly for some other reason than a reboot.

    Do you need to run it as another user? Either way it's hard to tell without seeing that plist. Have you looked at Lingon, it makes setting up launchd scripts easy, it creates the plist for you after you fill in a form.

  5. estorstenson thread starter macrumors member

    Jan 30, 2013
    It has a login, and more than one user. I want the job to launch without anyone having to login.

    Haven't seen lingon. Will look at it. Here is the plist file in /Library/LaunchAgents

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
    <plist version="1.0">
            <string>--user account-name</string>
    account-name is the username that owns the database. I've tried it with both account-name entries present and not in all combinations. What I want is for this to work like it does in linux, where you have a command line job launched at the start. I'm sure there is a way to do it, since all of this is being done by the system, presumably as root, which can launch jobs as any user on the system.

    Will look through these docs, but I suspect I've already been through them already.
  6. estorstenson thread starter macrumors member

    Jan 30, 2013
    Ah, I see where I was mistaken. LaunchAgents are specific to a user login and a daemon is system level. So, I was using the wrong type. Hopefully using a daemon will fix the issue.
  7. subsonix macrumors 68040

    Feb 2, 2008
    Yeah if you do want it to be system wide and not run under any particular user. But perhaps you can also check the system log at the time you tried last to see if there are any clues what happened.
  8. chown33, Jun 7, 2013
    Last edited: Jun 7, 2013

    chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    From what I can tell by googling, mysqld_safe is a shell script intended to start a daemonized version of mysql. Furtheremore, it appears to be designed for Linux and NetWare, neither of which use launchd.

    The behavior of launchd with respect to launch daemons differs in many ways from how daemons are managed on other systems.

    I recommend that you read more about exactly how launchd works, and then look at the shell code in mysqld_safe to understand exactly what it does. I suspect that at least one thing in the shell code is violating some rule of launchd. For example, the daemon(3) function in Linux is wrong to use with launchd.


    Google search terms: launchd mysql

Share This Page