<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="macos-installation-launchd">
      </a>
      2.4.3 Installing and Using the MySQL Launch Daemon
     </h3>
    </div>
   </div>
  </div>
  <p>
   macOS uses launch daemons to automatically start, stop, and manage
      processes and applications such as MySQL.
  </p>
  <p>
   By default, the installation package (DMG) on macOS installs a
      launchd file named
   <code class="filename">
    /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
   </code>
   that contains a plist definition similar to:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa57676519"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">&lt;?xml version=<span class="token atrule">"1.0"</span> encoding=<span class="token atrule">"UTF-8"</span>?&gt;
&lt;!DOCTYPE plist PUBLIC <span class="token atrule">"-//Apple Computer//DTD PLIST 1.0//EN"</span> <span class="token atrule">"http://www.apple.com/DTDs/PropertyList-1.0.dtd"</span>&gt;
&lt;plist version=<span class="token atrule">"1.0"</span>&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;             &lt;string&gt;com<span class="token punctuation">.</span>oracle<span class="token punctuation">.</span>oss<span class="token punctuation">.</span>mysql<span class="token punctuation">.</span>mysqld&lt;/string&gt;
    &lt;key&gt;ProcessType&lt;/key&gt;       &lt;string&gt;Interactive&lt;/string&gt;
    &lt;key&gt;Disabled&lt;/key&gt;          &lt;false/&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;         &lt;true/&gt;
    &lt;key&gt;KeepAlive&lt;/key&gt;         &lt;true/&gt;
    &lt;key&gt;SessionCreate&lt;/key&gt;     &lt;true/&gt;
    &lt;key&gt;LaunchOnlyOnce&lt;/key&gt;    &lt;false/&gt;
    &lt;key&gt;UserName&lt;/key&gt;          &lt;string&gt;_mysql&lt;/string&gt;
    &lt;key&gt;GroupName&lt;/key&gt;         &lt;string&gt;_mysql&lt;/string&gt;
    &lt;key&gt;ExitTimeOut&lt;/key&gt;       &lt;integer&gt;600&lt;/integer&gt;
    &lt;key&gt;Program&lt;/key&gt;           &lt;string&gt;/usr/local/mysql/bin/mysqld&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
            &lt;string&gt;/usr/local/mysql/bin/mysqld&lt;/string&gt;
            &lt;string&gt;<span class="token constant">--user</span><span class="token attr-value"><span class="token punctuation">=</span>_mysql&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--basedir</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--datadir</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql/data&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--plugin-dir</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql/lib/plugin&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--log-error</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql/data/mysqld.local.err&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--pid-file</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql/data/mysqld.local.pid&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--keyring-file-data</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql/keyring/keyring&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--early-plugin-load</span><span class="token attr-value"><span class="token punctuation">=</span>keyring_okv=keyring_okv.so&lt;/string&gt;</span>
        &lt;/array&gt;
    &lt;key&gt;WorkingDirectory&lt;/key&gt;  &lt;string&gt;/usr/local/mysql&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;</code></pre>
  </div>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    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
    <span class="emphasis">
     <em>
      d925f05f6d1b6ee5ce5451b596d6baed
     </em>
    </span>
    .
   </p>
  </div>
  <p>
   To enable the launchd service, you can either:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Open macOS system preferences and select the MySQL preference
          panel, and then execute
      <span class="guibutton">
       Start MySQL
          Server
      </span>
      .
     </p>
     <div class="figure">
      <a name="mac-installer-preference-pane-location-launchd">
      </a>
      <p class="title">
       <b>
        Figure 2.6 MySQL Preference Pane: Location
       </b>
      </p>
      <div class="figure-contents">
       <div class="mediaobject">
        <img alt='Shows "MySQL" typed into the macOS System Preferences search box, and a highlighted "MySQL" icon in the bottom left portion of the MySQL Preference Pane.' src="images/mac-installer-preference-pane-location.png" style="width: 100%; max-width: 668px;"/>
       </div>
      </div>
     </div>
     <br class="figure-break"/>
     <p>
      The
      <span class="guilabel">
       Instances
      </span>
      page includes an option to
          start or stop MySQL, and
      <span class="guibutton">
       Initialize
          Database
      </span>
      recreates the
      <code class="filename">
       data/
      </code>
      directory.
      <span class="guibutton">
       Uninstall
      </span>
      uninstalls MySQL
          Server and optionally the MySQL preference panel and launchd
          information.
     </p>
     <div class="figure">
      <a name="mac-installer-preference-pane-instances-launchd">
      </a>
      <p class="title">
       <b>
        Figure 2.7 MySQL Preference Pane: Instances
       </b>
      </p>
      <div class="figure-contents">
       <div class="mediaobject">
        <img alt='The left side shows a list of MySQL instances separated by "Active Instance", "Installed Instances", and "Data Directories" sections. The right side shows a "Stop MySQL Server" button, a check box titled "Start MySQL when your computer starts up", and "Initialize Database" and "Uninstall" buttons.' src="images/mac-installer-preference-pane-instances.png" style="width: 100%; max-width: 780px;"/>
       </div>
      </div>
     </div>
     <br class="figure-break"/>
    </li>
    <li class="listitem">
     <p>
      Or, manually load the launchd file.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa93315048"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">cd</span> /Library/LaunchDaemons
<span class="token prompt">$&gt; </span><span class="token command">sudo</span> launchctl load <span class="token property">-F</span> com<span class="token punctuation">.</span>oracle<span class="token punctuation">.</span>oss<span class="token punctuation">.</span>mysql<span class="token punctuation">.</span>mysqld<span class="token punctuation">.</span>plist</code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      To configure MySQL to automatically start at bootup, you can:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa79745492"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">sudo</span> launchctl load <span class="token property">-w</span> com<span class="token punctuation">.</span>oracle<span class="token punctuation">.</span>oss<span class="token punctuation">.</span>mysql<span class="token punctuation">.</span>mysqld<span class="token punctuation">.</span>plist</code></pre>
     </div>
    </li>
   </ul>
  </div>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    The upgrade process replaces your existing launchd file named
    <code class="filename">
     com.oracle.oss.mysql.mysqld.plist
    </code>
    .
   </p>
  </div>
  <p>
   Additional launchd related information:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      The plist entries override
      <code class="filename">
       my.cnf
      </code>
      entries, because they are passed in as command line arguments.
          For additional information about passing in program options,
          see
      <a class="xref" href="program-options.html" title="6.2.2 Specifying Program Options">
       Section 6.2.2, “Specifying Program Options”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      The
      <span class="bold">
       <strong>
        ProgramArguments
       </strong>
      </span>
      section
          defines the command line options that are passed into the
          program, which is the
      <code class="filename">
       mysqld
      </code>
      binary in
          this case.
     </p>
    </li>
    <li class="listitem">
     <p>
      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
      <code class="filename">
       my.cnf
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      If you edit the plist file, then uncheck the installer option
          when reinstalling or upgrading MySQL. Otherwise, your edited
          plist file is overwritten, and all edits are lost.
     </p>
    </li>
   </ul>
  </div>
  <p>
   Because the default plist definition defines several
   <span class="bold">
    <strong>
     ProgramArguments
    </strong>
   </span>
   , you might
      remove most of these arguments and instead rely upon your
   <code class="filename">
    my.cnf
   </code>
   MySQL configuration file to define
      them. For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa44509856"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">&lt;?xml version=<span class="token atrule">"1.0"</span> encoding=<span class="token atrule">"UTF-8"</span>?&gt;
&lt;!DOCTYPE plist PUBLIC <span class="token atrule">"-//Apple Computer//DTD PLIST 1.0//EN"</span> <span class="token atrule">"http://www.apple.com/DTDs/PropertyList-1.0.dtd"</span>&gt;
&lt;plist version=<span class="token atrule">"1.0"</span>&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;             &lt;string&gt;com<span class="token punctuation">.</span>oracle<span class="token punctuation">.</span>oss<span class="token punctuation">.</span>mysql<span class="token punctuation">.</span>mysqld&lt;/string&gt;
    &lt;key&gt;ProcessType&lt;/key&gt;       &lt;string&gt;Interactive&lt;/string&gt;
    &lt;key&gt;Disabled&lt;/key&gt;          &lt;false/&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;         &lt;true/&gt;
    &lt;key&gt;KeepAlive&lt;/key&gt;         &lt;true/&gt;
    &lt;key&gt;SessionCreate&lt;/key&gt;     &lt;true/&gt;
    &lt;key&gt;LaunchOnlyOnce&lt;/key&gt;    &lt;false/&gt;
    &lt;key&gt;UserName&lt;/key&gt;          &lt;string&gt;_mysql&lt;/string&gt;
    &lt;key&gt;GroupName&lt;/key&gt;         &lt;string&gt;_mysql&lt;/string&gt;
    &lt;key&gt;ExitTimeOut&lt;/key&gt;       &lt;integer&gt;600&lt;/integer&gt;
    &lt;key&gt;Program&lt;/key&gt;           &lt;string&gt;/usr/local/mysql/bin/mysqld&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
            &lt;string&gt;/usr/local/mysql/bin/mysqld&lt;/string&gt;
            &lt;string&gt;<span class="token constant">--user</span><span class="token attr-value"><span class="token punctuation">=</span>_mysql&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--basedir</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--datadir</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql/data&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--plugin-dir</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql/lib/plugin&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--log-error</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql/data/mysqld.local.err&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--pid-file</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql/data/mysqld.local.pid&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--keyring-file-data</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql/keyring/keyring&lt;/string&gt;</span>
            &lt;string&gt;<span class="token constant">--early-plugin-load</span><span class="token attr-value"><span class="token punctuation">=</span>keyring_okv=keyring_okv.so&lt;/string&gt;</span>
        &lt;/array&gt;
    &lt;key&gt;WorkingDirectory&lt;/key&gt;  &lt;string&gt;/usr/local/mysql&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;</code></pre>
  </div>
  <p>
   In this case, the
   <a class="link" href="server-system-variables.html#sysvar_basedir">
    <code class="literal">
     basedir
    </code>
   </a>
   ,
   <a class="link" href="server-system-variables.html#sysvar_datadir">
    <code class="literal">
     datadir
    </code>
   </a>
   ,
   <a class="link" href="server-system-variables.html#sysvar_plugin_dir">
    <code class="literal">
     plugin_dir
    </code>
   </a>
   ,
   <a class="link" href="server-system-variables.html#sysvar_log_error">
    <code class="literal">
     log_error
    </code>
   </a>
   ,
   <a class="link" href="server-system-variables.html#sysvar_pid_file">
    <code class="literal">
     pid_file
    </code>
   </a>
   , and
      ﻿
   <a class="link" href="server-options.html#option_mysqld_early-plugin-load">
    <code class="option">
     --early-plugin-load
    </code>
   </a>
   options were
      removed from the default plist
   <span class="emphasis">
    <em>
     ProgramArguments
    </em>
   </span>
   definition, which you might
      have defined in
   <code class="filename">
    my.cnf
   </code>
   instead.
  </p>
 </div>
 <br/>
</div>
