Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start MariaDB (like MySQL) on macOS, on BOOT?

Tags:

macos

mariadb

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.

like image 243
l008com Avatar asked Mar 17 '18 07:03

l008com


1 Answers

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.

like image 60
l008com Avatar answered Nov 18 '22 12:11

l008com