<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="problems-with-mysql-sock">
      </a>
      B.3.3.6 How to Protect or Change the MySQL Unix Socket File
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045053781216">
  </a>
  <a class="indexterm" name="idm46045053779728">
  </a>
  <p>
   The default location for the Unix socket file that the server
          uses for communication with local clients is
   <code class="filename">
    /tmp/mysql.sock
   </code>
   . (For some distribution
          formats, the directory might be different, such as
   <code class="filename">
    /var/lib/mysql
   </code>
   for RPMs.)
  </p>
  <p>
   On some versions of Unix, anyone can delete files in the
   <code class="filename">
    /tmp
   </code>
   directory or other similar
          directories used for temporary files. If the socket file is
          located in such a directory on your system, this might cause
          problems.
  </p>
  <p>
   On most versions of Unix, you can protect your
   <code class="filename">
    /tmp
   </code>
   directory so that files can be
          deleted only by their owners or the superuser
          (
   <code class="literal">
    root
   </code>
   ). To do this, set the
   <code class="literal">
    sticky
   </code>
   bit on the
   <code class="filename">
    /tmp
   </code>
   directory by logging in as
   <code class="literal">
    root
   </code>
   and using
          the following command:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa54509392"><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">chmod</span> +t /tmp</code></pre>
  </div>
  <p>
   You can check whether the
   <code class="literal">
    sticky
   </code>
   bit is set
          by executing
   <code class="literal">
    ls -ld /tmp
   </code>
   . If the last
          permission character is
   <code class="literal">
    t
   </code>
   , the bit is set.
  </p>
  <a class="indexterm" name="idm46045053766368">
  </a>
  <p>
   Another approach is to change the place where the server
          creates the Unix socket file. If you do this, you should also
          let client programs know the new location of the file. You can
          specify the file location in several ways:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Specify the path in a global or local option file. For
              example, put the following lines in
      <code class="literal">
       /etc/my.cnf
      </code>
      :
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa47352996"><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-ini"><span class="token selector">[mysqld]</span>
<span class="token constant">socket</span><span class="token attr-value"><span class="token punctuation">=</span>/path/to/socket</span>

<span class="token selector">[client]</span>
<span class="token constant">socket</span><span class="token attr-value"><span class="token punctuation">=</span>/path/to/socket</span></code></pre>
     </div>
     <p>
      See
      <a class="xref" href="option-files.html" title="6.2.2.2 Using Option Files">
       Section 6.2.2.2, “Using Option Files”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      Specify a
      <a class="link" href="connection-options.html#option_general_socket">
       <code class="option">
        --socket
       </code>
      </a>
      option
              on the command line to
      <a class="link" href="mysqld-safe.html" title="6.3.2 mysqld_safe — MySQL Server Startup Script">
       <span class="command">
        <strong>
         mysqld_safe
        </strong>
       </span>
      </a>
      and
              when you run client programs.
     </p>
    </li>
    <li class="listitem">
     <p>
      Set the
      <code class="literal">
       MYSQL_UNIX_PORT
      </code>
      environment
              variable to the path of the Unix socket file.
     </p>
    </li>
    <li class="listitem">
     <p>
      Recompile MySQL from source to use a different default
              Unix socket file location. Define the path to the file
              with the
      <a class="link" href="source-configuration-options.html#option_cmake_mysql_unix_addr">
       <code class="option">
        MYSQL_UNIX_ADDR
       </code>
      </a>
      option when you run
      <span class="command">
       <strong>
        CMake
       </strong>
      </span>
      . See
      <a class="xref" href="source-configuration-options.html" title="2.8.7 MySQL Source-Configuration Options">
       Section 2.8.7, “MySQL Source-Configuration Options”
      </a>
      .
     </p>
    </li>
   </ul>
  </div>
  <p>
   You can test whether the new socket location works by
          attempting to connect to the server with this command:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa63326971"><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">mysqladmin</span> <span class="token constant">--socket</span><span class="token attr-value"><span class="token punctuation">=</span>/path/to/socket</span> version</code></pre>
  </div>
 </div>
 <br/>
</div>
