0

I 've installed mysql server with brew, and i need to run manually this command each time my computer start to make it work with an application that I can't edit.

sudo mkdir -p -- /var/run/mysqld/ ; sudo ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock

What I can do to call this automatically? I tried with Automator, but I don't want to enter my password each time, what is the right way to run this or to fix this? (may changing permissions and running this as normal user)

Mysql is running with my normal user, not root.

  • Did you try and AppleScript? – bretonics Dec 22 '14 at 15:05
1

On OS X Yosemite you should add the script in:

/Library/LaunchDaemons

using this name for the script:

com.mysql.mysql.plist

and this content:

<!--?xml version="1.0" encoding="UTF-8"?-->
<plist version="1.0">
  <dict>
    <key>KeepAlive</key>
    <dict>
       <key>SuccessfulExit</key>
       <false/>
    </dict>
    <key>Label</key>
    <string>com.mysql.mysqld</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/mysql/bin/mysqld_safe</string>
      <string>--user=mysql</string>
    </array>
  </dict>
</plist>

you will get MySQL started automatically every time you reboot the Mac.

be sure to set proper privileges to the script:

sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist

Just tested on OS X 10.10.2 while moving out of MAMP PRO and it works like a breeze :-)

0

You can create Launch Agent and place it inside /Library/LaunchAgents directory. This will ensure Your code to be run as root. Here's Apple documentation about Launch Agents. You'll need to create plist file, it'll look like this:

<?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">
<dict>
    <key>Label</key>
    <string>com.mysql.script</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/sh</string>
        <string>-c</string>
        <string>/path/to/your/script.sh</string>
    </array>
    <key>LimitLoadToSessionType</key>
    <string>Aqua</string>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Save it and chown it as root. Your script should also be owned by root and be executable as well. With this Your script will be run always after logging in.

NOTE: change path to Your script in this plist file.

You must log in to answer this question.

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