<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="setting-environment-variables">
      </a>
      6.2.9 Setting Environment Variables
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045322053184">
  </a>
  <p>
   Environment variables can be set at the command prompt to affect
      the current invocation of your command processor, or set
      permanently to affect future invocations. To set a variable
      permanently, you can set it in a startup file or by using the
      interface provided by your system for this purpose. Consult the
      documentation for your command interpreter for specific details.
   <a class="xref" href="environment-variables.html" title="6.9 Environment Variables">
    Section 6.9, “Environment Variables”
   </a>
   , lists all environment
      variables that affect MySQL program operation.
  </p>
  <p>
   To specify a value for an environment variable, use the syntax
      appropriate for your command processor. For example, on Windows,
      you can set the
   <code class="literal">
    USER
   </code>
   variable to specify your
      MySQL account name. To do so, use this syntax:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa28193208"><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">SET USER<span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">your_name</em></span></code></pre>
  </div>
  <p>
   The syntax on Unix depends on your shell. Suppose that you want to
      specify the TCP/IP port number using the
   <code class="literal">
    MYSQL_TCP_PORT
   </code>
   variable. Typical syntax (such
      as for
   <span class="command">
    <strong>
     sh
    </strong>
   </span>
   ,
   <span class="command">
    <strong>
     ksh
    </strong>
   </span>
   ,
   <span class="command">
    <strong>
     bash
    </strong>
   </span>
   ,
   <span class="command">
    <strong>
     zsh
    </strong>
   </span>
   , and so on) is as
      follows:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa86594534"><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_TCP_PORT<span class="token attr-value"><span class="token punctuation">=</span>3306</span>
export MYSQL_TCP_PORT</code></pre>
  </div>
  <p>
   The first command sets the variable, and the
   <code class="literal">
    export
   </code>
   command exports the variable to the
      shell environment so that its value becomes accessible to MySQL
      and other processes.
  </p>
  <p>
   For
   <span class="command">
    <strong>
     csh
    </strong>
   </span>
   and
   <span class="command">
    <strong>
     tcsh
    </strong>
   </span>
   , use
   <span class="command">
    <strong>
     setenv
    </strong>
   </span>
   to make the shell variable available to
      the environment:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa45821678"><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">setenv MYSQL_TCP_PORT 3306</code></pre>
  </div>
  <p>
   The commands to set environment variables can be executed at your
      command prompt to take effect immediately, but the settings
      persist only until you log out. To have the settings take effect
      each time you log in, use the interface provided by your system or
      place the appropriate command or commands in a startup file that
      your command interpreter reads each time it starts.
  </p>
  <p>
   On Windows, you can set environment variables using the System
      Control Panel (under Advanced).
  </p>
  <p>
   On Unix, typical shell startup files are
   <code class="filename">
    .bashrc
   </code>
   or
   <code class="filename">
    .bash_profile
   </code>
   for
   <span class="command">
    <strong>
     bash
    </strong>
   </span>
   , or
   <code class="filename">
    .tcshrc
   </code>
   for
   <span class="command">
    <strong>
     tcsh
    </strong>
   </span>
   .
  </p>
  <p>
   Suppose that your MySQL programs are installed in
   <code class="literal">
    /usr/local/mysql/bin
   </code>
   and that you want to make
      it easy to invoke these programs. To do this, set the value of the
   <code class="literal">
    PATH
   </code>
   environment variable to include that
      directory. For example, if your shell is
   <span class="command">
    <strong>
     bash
    </strong>
   </span>
   ,
      add the following line to your
   <code class="filename">
    .bashrc
   </code>
   file:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa8432243"><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">PATH<span class="token attr-value"><span class="token punctuation">=</span>${PATH}:/usr/local/mysql/bin</span></code></pre>
  </div>
  <p>
   <span class="command">
    <strong>
     bash
    </strong>
   </span>
   uses different startup files for login and
      nonlogin shells, so you might want to add the setting to
   <code class="filename">
    .bashrc
   </code>
   for login shells and to
   <code class="filename">
    .bash_profile
   </code>
   for nonlogin shells to make
      sure that
   <code class="literal">
    PATH
   </code>
   is set regardless.
  </p>
  <p>
   If your shell is
   <span class="command">
    <strong>
     tcsh
    </strong>
   </span>
   , add the following line
      to your
   <code class="filename">
    .tcshrc
   </code>
   file:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa33997896"><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">setenv PATH $<span class="token punctuation">{</span>PATH<span class="token punctuation">}</span><span class="token punctuation">:</span>/usr/local/mysql/bin</code></pre>
  </div>
  <p>
   If the appropriate startup file does not exist in your home
      directory, create it with a text editor.
  </p>
  <p>
   After modifying your
   <code class="literal">
    PATH
   </code>
   setting, open a new
      console window on Windows or log in again on Unix so that the
      setting goes into effect.
  </p>
 </div>
 <br/>
</div>
