I currently use Valet to develop sites, and many of those sites need SQL databases. To host SQL databases, I run a mariaDB server from the Terminal. In order to start the MySQL server so that I can connect to the databases, I run the command: sudo mysql.server start I want the server to start on login, so normally I would just have this command execute on login, but it requires the sudo command. What do I change and how do I change it so that I do not need the sudo part of the command and I can just start the server on login?

  • 1
    See if this Q&A helps. It's not a duplicate question but it has info that might assist you.
    – fsb
    Commented Jan 13, 2017 at 17:31

1 Answer 1


The best way to do this is to create a launchd .plist, copy it to ~/Library/LaunchAgents and let the system handle it for you.

Sample .plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

I prefer to use the file naming convention com.user.<name of function>.plist when naming them so I can easily identify what is loaded and what is not.

Next, you need to load this .plist as root so it runs as root

$ sudo launchctl load com.user.startMySQL.plist

To verify that it has loaded you can issue the command sudo launchctl list and the command mysql to initiate a connection to the MySQL service.

Please note that this is just a simple example - you may wish to create a script to check to see if mysqld is already running before launching it.

  • but it sounds like I will have to run this command every time I want to use the server, so I dont see how this is better than what I do now. actually I was just looking for which permissions or owner to change to make this command runnable by me without sudo, so that I can then just execute this command on login somehow.
    – brothman01
    Commented Jan 15, 2017 at 3:28
  • You only have to do this once. It will launch MySQL automatically every time you log in
    – Allan
    Commented Jan 15, 2017 at 5:06
  • oh ok thanks Tell me if understand this correctly: 'launchd' is a daemon that starts at launch and runs every job in 'launchctl'. In order to add a job to launchctl, define it in a .plist file and copy that file to ~/Library/LaunchAgents, then load the plist into launchctl with$ launchctl load com.user.startMySQL.plist and the reason a path does not have to be given in the command is that a file name is sufficient as long as it is a file in the 'LaunchAgents' directory because launchctl looks in that directory. Once loaded into launchctl, launchd will run the new job on login.
    – brothman01
    Commented Jan 18, 2017 at 3:20
  • That's basically correct. I have written about launchd in more detail in this answer Personally, I wourld start your server on boot rather than on login, but whatever suits you best...
    – Allan
    Commented Jan 18, 2017 at 13:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .