6

I've installed MariaDB on a fresh macOS 10.11 server setup using HomeBrew. The server runs great when I start it manually, but I have been unable to get it to start automatically at boot (not login). I used sudo brew services start mariadb to create a launchd script in /Library/LaunchDaemons but it doesn't work. No running mariadb, no mariadb error log. It seems to silently fail. There must be some relevant log somewhere but I don't know where.

When that didn't work, I tried making my own launchd script, first having it run mysql.server start, but that failed. With full path and proper permissions, but it would never work.

Then I copied some of the code from the homebrew's own launchd plist and made my own plist that runs mysqld_safe, which also doesn't work:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE truncated for easier forum viewing>
<plist version="1.0">
<dict>
    <key>Label</key>
        <string>com.macfixer.mariadb</string>
    <key>ProgramArguments</key>
        <array>
            <string>/usr/local/opt/mariadb/bin/mysqld_safe</string>
            <string>--datadir=/usr/local/var/mysql</string>
        </array>
    <key>WorkingDirectory</key>
        <string>/usr/local/var</string>
        
    <key>Disabled</key>
        <false/>
    <key>RunAtLoad</key>
        <true/>
        
    <key>StandardOutPath</key>
        <string>/logs/mariadb.out.log</string>
    <key>StandardErrorPath</key>
        <string>/logs/mariadb.error.log</string>
</dict>
</plist>

The above leaves no trace in the mariadb error log, or the StandardErrorPath error log. However it does leave some content in the StandardOutPath log. And it looks like mariadb is starting up, it just.... isn't.

180326 08:37:27 mysqld_safe Logging to '/usr/local/var/log/mysqld-error.log'.

180326 08:37:28 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql

But again, if I run mysql.server start once the computer boots and logs in, MariaDB starts right up no problem at all. But when started from launchd, it seems to just silently quit immediately.

6
  • Have you tried using absolute paths to the binaries? The PATH environment variable is probably different between your terminal and launchd. Mar 17, 2018 at 8:00
  • Yup, all my launchd plists are using full paths.
    – l008com
    Mar 17, 2018 at 9:05
  • Did you check this question on StackExchange? I know it's for mysql, but it could be useful for MariaDB since they're somewhat similar. It was a permissions issue on that particular question, but it basically can be anything. Did you add the StandardErrorPath to your plist? Mar 19, 2018 at 2:12
  • I set StandardErrorPath and StandardOutPath in my .plist, but neither results in any output. I double-checked the permissions and they are correct. I did notice that I do get one error in the system log, I'll add it to the main post above rather than add it to this comment.
    – l008com
    Mar 19, 2018 at 11:02
  • Try running brew ls -verbose mariadb to find out where its config and error files might be hiding. Mar 29, 2018 at 8:55

1 Answer 1

3

Turns out this very annoying problem has a very simple answer.

Make the MariaDB installation owned by _mysql: sudo chown -R _mysql: /usr/local/var/mysql

And that's it! After doing that, it works perfectly.

Why doesn't the homebrew installer take care of the permissions of software it installs? Why didn't the database write to its own error log saying there was a permissions problem? Why didn't stderr or stdout from the launchd script hint that there was a permissions problem, or ANY problem at all?

... I have no idea. I'll just call it a bug and move on. But changing permissions on the mariadb install folder completely fixed the problem. And that is a huge relief.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.