<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="program-options">
      </a>
      6.2.2 Specifying Program Options
     </h3>
    </div>
   </div>
  </div>
  <div class="toc">
   <dl class="toc">
    <dt>
     <span class="section">
      <a href="command-line-options.html">
       6.2.2.1 Using Options on the Command Line
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="option-files.html">
       6.2.2.2 Using Option Files
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="option-file-options.html">
       6.2.2.3 Command-Line Options that Affect Option-File Handling
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="option-modifiers.html">
       6.2.2.4 Program Option Modifiers
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="program-variables.html">
       6.2.2.5 Using Options to Set Program Variables
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="option-defaults-equals.html">
       6.2.2.6 Option Defaults, Options Expecting Values, and the = Sign
      </a>
     </span>
    </dt>
   </dl>
  </div>
  <p>
   There are several ways to specify options for MySQL programs:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      List the options on the command line following the program
          name. This is common for options that apply to a specific
          invocation of the program.
     </p>
    </li>
    <li class="listitem">
     <p>
      List the options in an option file that the program reads when
          it starts. This is common for options that you want the
          program to use each time it runs.
     </p>
    </li>
    <li class="listitem">
     <p>
      List the options in environment variables (see
      <a class="xref" href="setting-environment-variables.html" title="6.2.9 Setting Environment Variables">
       Section 6.2.9, “Setting Environment Variables”
      </a>
      ). This method
          is useful for options that you want to apply each time the
          program runs. In practice, option files are used more commonly
          for this purpose, but
      <a class="xref" href="multiple-unix-servers.html" title="7.8.3 Running Multiple MySQL Instances on Unix">
       Section 7.8.3, “Running Multiple MySQL Instances on Unix”
      </a>
      ,
          discusses one situation in which environment variables can be
          very helpful. It describes a handy technique that uses such
          variables to specify the TCP/IP port number and Unix socket
          file for the server and for client programs.
     </p>
    </li>
   </ul>
  </div>
  <p>
   Options are processed in order, so if an option is specified
      multiple times, the last occurrence takes precedence. The
      following command causes
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   to connect to
      the server running on
   <code class="literal">
    localhost
   </code>
   :
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa58488372"><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">mysql <span class="token property">-h</span> example<span class="token punctuation">.</span>com <span class="token property">-h</span> localhost</code></pre>
  </div>
  <p>
   There is one exception: For
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   , the
   <span class="emphasis">
    <em>
     first
    </em>
   </span>
   instance of the
   <a class="link" href="server-options.html#option_mysqld_user">
    <code class="option">
     --user
    </code>
   </a>
   option is used as a security
      precaution, to prevent a user specified in an option file from
      being overridden on the command line.
  </p>
  <p>
   If conflicting or related options are given, later options take
      precedence over earlier options. The following command runs
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   in
   <span class="quote">
    “
    <span class="quote">
     no column names
    </span>
    ”
   </span>
   mode:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa75701261"><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">mysql <span class="token property">--column-names</span> <span class="token property">--skip-column-names</span></code></pre>
  </div>
  <a class="indexterm" name="idm46045324240928">
  </a>
  <a class="indexterm" name="idm46045324239440">
  </a>
  <p>
   MySQL programs determine which options are given first by
      examining environment variables, then by processing option files,
      and then by checking the command line. Because later options take
      precedence over earlier ones, the processing order means that
      environment variables have the lowest precedence and command-line
      options the highest.
  </p>
  <a class="indexterm" name="idm46045324237568">
  </a>
  <a class="indexterm" name="idm46045324236480">
  </a>
  <p>
   For the server, one exception applies: The
   <span class="command">
    <strong>
     mysqld-auto.cnf
    </strong>
   </span>
   option file in the data
      directory is processed last, so it takes precedence even over
      command-line options.
  </p>
  <p>
   You can take advantage of the way that MySQL programs process
      options by specifying default option values for a program in an
      option file. That enables you to avoid typing them each time you
      run the program while enabling you to override the defaults if
      necessary by using command-line options.
  </p>
 </div>
 <br/>
</div>
