Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.3Mb
PDF (A4) - 37.4Mb
PDF (RPM) - 36.7Mb
HTML Download (TGZ) - 10.2Mb
HTML Download (Zip) - 10.2Mb
HTML Download (RPM) - 8.8Mb
Man Pages (TGZ) - 210.2Kb
Man Pages (Zip) - 318.2Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual  /  ...  /  Installing a MySQL Launch Daemon

2.4.3 Installing a MySQL Launch Daemon

OS X uses launch daemons to automatically start, stop, and manage processes and applications such as MySQL.

Note

Before MySQL 5.7.8, the OS X builds installed startup items instead of launchd daemons. However, startup items do not function as of OS X 10.10 (Yosemite). The OS X builds now install launchd daemons.

By default, the installation package (DMG) on OS X installs a launchd file named /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist that contains a plist definition similar to:


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>             <string>com.oracle.oss.mysql.mysqld</string>
    <key>ProcessType</key>       <string>Interactive</string>
    <key>Disabled</key>          <false/>
    <key>RunAtLoad</key>         <true/>
    <key>KeepAlive</key>         <true/>
    <key>SessionCreate</key>     <true/>
    <key>LaunchOnlyOnce</key>    <false/>
    <key>UserName</key>          <string>_mysql</string>
    <key>GroupName</key>         <string>_mysql</string>
    <key>ExitTimeOut</key>       <integer>600</integer>
    <key>Program</key>           <string>/usr/local/mysql/bin/mysqld</string>
    <key>ProgramArguments</key>
        <array>
            <string>/usr/local/mysql/bin/mysqld</string>
            <string>--user=_mysql</string>
            <string>--basedir=/usr/local/mysql</string>
            <string>--datadir=/usr/local/mysql/data</string>
            <string>--plugin-dir=/usr/local/mysql/lib/plugin</string>
            <string>--log-error=/usr/local/mysql/data/mysqld.local.err</string>
            <string>--pid-file=/usr/local/mysql/data/mysqld.local.pid</string>
        </array>
    <key>WorkingDirectory</key>  <string>/usr/local/mysql</string>
</dict>
</plist>

Note

Some users report that adding a plist DOCTYPE declaration causes the launchd operation to fail, despite it passing the lint check. We suspect it's a copy-n-paste error. The md5 checksum of a file containing the above snippet is 24710a27dc7a28fb7ee6d825129cd3cf.

To enable the launchd service, you can either:

  • Click Start MySQL Server from the MySQL preference pane.

    Figure 2.29 MySQL Preference Pane: Location

    MySQL Preference Pane: Location

    Figure 2.30 MySQL Preference Pane: Usage

    MySQL Preference Pane: Usage

  • Or, manually load the launchd file.

    shell> cd /Library/LaunchDaemons
    shell> sudo launchctl load -F com.oracle.oss.mysql.mysqld.plist
            
  • To configure MySQL to automatically start at bootup, you can:

    shell> sudo launchctl load -w com.oracle.oss.mysql.mysqld.plist
    
Note

When upgrading MySQL server, the launchd installation process will remove the old startup items that were installed with MySQL server 5.7.7 and below.

Also, upgrading will replace your existing launchd file of the same name.

Additional launchd related information:

  • The plist entries override my.cnf entries, because they are passed in as command line arguments. For additional information about passing in program options, see Section 5.2.3, “Specifying Program Options”.

  • The ProgramArguments section defines the command line options that are passed into the program, which is the mysqld binary in this case.

  • The default plist definition is written with less sophisticated use cases in mind. For more complicated setups, you may want to remove some of the arguments and instead rely on a MySQL configuration file, such as my.cnf.

  • If you edit the plist file, then uncheck the installer option when reinstalling or upgrading MySQL. Otherwise, your edited plist file will be overwritten, and all edits will be lost.

Because the default plist definition defines several ProgramArguments, you might remove most of these arguments and instead rely upon your my.cnf MySQL configuration file to define them. For example:


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>             <string>com.oracle.oss.mysql.mysqld</string>
    <key>ProcessType</key>       <string>Interactive</string>
    <key>Disabled</key>          <false/>
    <key>RunAtLoad</key>         <true/>
    <key>KeepAlive</key>         <true/>
    <key>SessionCreate</key>     <true/>
    <key>LaunchOnlyOnce</key>    <false/>
    <key>UserName</key>          <string>_mysql</string>
    <key>GroupName</key>         <string>_mysql</string>
    <key>ExitTimeOut</key>       <integer>600</integer>
    <key>Program</key>           <string>/usr/local/mysql/bin/mysqld</string>
    <key>WorkingDirectory</key>  <string>/usr/local/mysql</string>
    <key>ProgramArguments</key>
        <array>
            <string>/usr/local/mysql/bin/mysqld</string>
            <string>--user=_mysql</string>
        </array>
</dict>
</plist>

   

In this case, the basedir, datadir, plugin_dir, log_error, and pid_file options were removed from the plist definition, and then you you might define them in my.cnf.


User Comments
  Posted by Jacob Nikom on April 15, 2015
Previously it was user who managed the MySQL server - start and stop it. In OSX user manages MySQL daemon who in turn manages MySQL server.

To disable MySQL service (stop the daemon) use the command
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysql.plist

This command stops MySQL server as well as daemon.

You can see MySQL server process using commands:
shell> sudo launchctl list|grep mysql
Password:
98201 0 com.mysql.mysqld

If you MySQL server is running, but you don't see it in the list, it means the installation probably was not correct
  Posted by Jacob Nikom on April 15, 2015
To tell MySQL daemon (service) to start and stop MySQL server use the following commands:
shell> sudo launchctl start com.mysql.mysqld
shell> sudo launchctl stop com.mysql.mysqld

Wait until the server stops - there is no indication on the command line that the server is stopping.

sudo is important, but they could be run under root user account without sudo
  Posted by Mark Stevens on July 10, 2015
I had to remove the DOCTYPE line from the plist file as I was getting the error "Invalid property list" when I tried the launchctl command.

Hope this helps.
Sign Up Login You must be logged in to post a comment.