Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > media > main-testing > by-pkgid > b1e2421f2416edfc24c5845fbc1c5a2e > files > 117

mysql-doc-5.0.51a-8mdv2008.1.x86_64.rpm

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Chapter 4. Using MySQL Programs</title><link rel="stylesheet" href="mysql-html.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.69.1"><link rel="start" href="index.html" title="MySQL 5.0 Reference Manual"><link rel="up" href="index.html" title="MySQL 5.0 Reference Manual"><link rel="prev" href="tutorial.html" title="Chapter 3. Tutorial"><link rel="next" href="server-administration.html" title="Chapter 5. MySQL Server Administration"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 4. Using MySQL Programs</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="tutorial.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="server-administration.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="using-mysql-programs"></a>Chapter 4. Using MySQL Programs</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="using-mysql-programs.html#program-overview">4.1. Overview of MySQL Programs</a></span></dt><dt><span class="section"><a href="using-mysql-programs.html#invoking-programs">4.2. Invoking MySQL Programs</a></span></dt><dt><span class="section"><a href="using-mysql-programs.html#program-options">4.3. Specifying Program Options</a></span></dt><dd><dl><dt><span class="section"><a href="using-mysql-programs.html#command-line-options">4.3.1. Using Options on the Command Line</a></span></dt><dt><span class="section"><a href="using-mysql-programs.html#option-files">4.3.2. Using Option Files</a></span></dt><dt><span class="section"><a href="using-mysql-programs.html#program-variables">4.3.3. Using Options to Set Program Variables</a></span></dt></dl></dd><dt><span class="section"><a href="using-mysql-programs.html#setting-environment-variables">4.4. Setting Environment Variables</a></span></dt></dl></div><p>
    This chapter provides a brief overview of the command-line programs
    provided by MySQL AB and discusses the general syntax for specifying
    options when you run these programs. Most programs have options that
    are specific to their own operation, but the option syntax is
    similar for all of them. Later chapters provide more detailed
    descriptions of individual programs, including which options they
    recognize.
  </p><p>
    MySQL AB also provides three GUI client programs for use with MySQL
    Server:
  </p><div class="itemizedlist"><ul type="disc"><li><p>
        MySQL Administrator: This tool is used for administering MySQL
        servers, databases, tables, and user accounts.
      </p></li><li><p>
        MySQL Query Browser: This graphical tool is provided by MySQL AB
        for creating, executing, and optimizing queries on MySQL
        databases.
      </p></li><li><p>
        MySQL Migration Toolkit: This tool helps you migrate schemas and
        data from other relational database management systems for use
        with MySQL.
      </p></li></ul></div><p>
    These GUI programs each have their own manuals that you can access
    at <a href="http://dev.mysql.com/doc/" target="_top">http://dev.mysql.com/doc/</a>.
  </p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="program-overview"></a>4.1. Overview of MySQL Programs</h2></div></div></div><p>
      MySQL AB provides several types of programs:
    </p><div class="itemizedlist"><ul type="disc"><li><p>
          The MySQL server and server startup scripts:
        </p><div class="itemizedlist"><ul type="circle"><li><p>
              <span><strong class="command">mysqld</strong></span> is the MySQL server.
            </p></li><li><p>
              <span><strong class="command">mysqld_safe</strong></span>,
              <span><strong class="command">mysql.server</strong></span>, and
              <span><strong class="command">mysqld_multi</strong></span> are server startup
              scripts.
            </p></li><li><p>
              <span><strong class="command">mysql_install_db</strong></span> initializes the data
              directory and the initial databases.
            </p></li><li><p>
              MySQL Instance Manager monitors and manages MySQL Server
              instances.
            </p></li></ul></div><p>
          <a href="server-administration.html" title="Chapter 5. MySQL Server Administration">Chapter 5, <i>MySQL Server Administration</i></a>, discusses these
          programs further.
        </p></li><li><p>
          Client programs that access the server:
        </p><div class="itemizedlist"><ul type="circle"><li><p>
              <span><strong class="command">mysql</strong></span> is a command-line client for
              executing SQL statements interactively or in batch mode.
            </p></li><li><p>
              <span><strong class="command">mysqladmin</strong></span> is an administrative client.
            </p></li><li><p>
              <span><strong class="command">mysqlcheck</strong></span> performs table maintenance
              operations.
            </p></li><li><p>
              <span><strong class="command">mysqldump</strong></span> and
              <span><strong class="command">mysqlhotcopy</strong></span> make database backups.
            </p></li><li><p>
              <span><strong class="command">mysqlimport</strong></span> imports data files.
            </p></li><li><p>
              <span><strong class="command">mysqlshow</strong></span> displays information about
              databases and tables.
            </p></li></ul></div><p>
          <a href="client-utility-programs.html" title="Chapter 7. Client and Utility Programs">Chapter 7, <i>Client and Utility Programs</i></a>, discusses these
          programs further.
        </p></li><li><p>
          Utility programs that operate independently of the server:
        </p><div class="itemizedlist"><ul type="circle"><li><p>
              <span><strong class="command">myisamchk</strong></span> performs table maintenance
              operations.
            </p></li><li><p>
              <span><strong class="command">myisampack</strong></span> produces compressed,
              read-only tables.
            </p></li><li><p>
              <span><strong class="command">mysqlbinlog</strong></span> is a tool for processing
              binary log files.
            </p></li><li><p>
              <span><strong class="command">perror</strong></span> displays the meaning of error
              codes.
            </p></li></ul></div><p>
          <a href="client-utility-programs.html" title="Chapter 7. Client and Utility Programs">Chapter 7, <i>Client and Utility Programs</i></a>, discusses these
          programs further.
        </p></li></ul></div><p>
      Most MySQL distributions include all of these programs, except for
      those programs that are platform-specific. (For example, the
      server startup scripts are not used on Windows.) The exception is
      that RPM distributions are more specialized. There is one RPM for
      the server, another for client programs, and so forth. If you
      appear to be missing one or more programs, see
      <a href="installing.html" title="Chapter 2. Installing and Upgrading MySQL">Chapter 2, <i>Installing and Upgrading MySQL</i></a>, for information on types of
      distributions and what they contain. It may be that you have a
      distribution that does not include all programs and you need to
      install something else.
    </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="invoking-programs"></a>4.2. Invoking MySQL Programs</h2></div></div></div><p>
      To invoke a MySQL program from the command line (that is, from
      your shell or command prompt), enter the program name followed by
      any options or other arguments needed to instruct the program what
      you want it to do. The following commands show some sample program
      invocations. “<span class="quote"><code class="literal">shell&gt;</code></span>”
      represents the prompt for your command interpreter; it is not part
      of what you type. The particular prompt you see depends on your
      command interpreter. Typical prompts are <code class="literal">$</code> for
      <span><strong class="command">sh</strong></span> or <span><strong class="command">bash</strong></span>,
      <code class="literal">%</code> for <span><strong class="command">csh</strong></span> or
      <span><strong class="command">tcsh</strong></span>, and <code class="literal">C:\&gt;</code> for the
      Windows <span><strong class="command">command.com</strong></span> or
      <span><strong class="command">cmd.exe</strong></span> command interpreters.
    </p><pre class="programlisting">shell&gt; <strong class="userinput"><code>mysql --user=root test</code></strong>
shell&gt; <strong class="userinput"><code>mysqladmin extended-status variables</code></strong>
shell&gt; <strong class="userinput"><code>mysqlshow --help</code></strong>
shell&gt; <strong class="userinput"><code>mysqldump -u root personnel</code></strong>
</pre><p>
      Arguments that begin with a single or double dash
      (“<span class="quote"><code class="literal">-</code></span>”,
      “<span class="quote"><code class="literal">--</code></span>”) are option arguments.
      Options typically specify the type of connection a program should
      make to the server or affect its operational mode. Option syntax
      is described in <a href="using-mysql-programs.html#program-options" title="4.3. Specifying Program Options">Section 4.3, “Specifying Program Options”</a>.
    </p><p>
      Non-option arguments (arguments with no leading dash) provide
      additional information to the program. For example, the
      <span><strong class="command">mysql</strong></span> program interprets the first non-option
      argument as a database name, so the command <code class="literal">mysql
      --user=root test</code> indicates that you want to use the
      <code class="literal">test</code> database.
    </p><p>
      Later sections that describe individual programs indicate which
      options a program understands and describe the meaning of any
      additional non-option arguments.
    </p><p>
      Some options are common to a number of programs. The most common
      of these are the <code class="option">--host</code> (or <code class="option">-h</code>),
      <code class="option">--user</code> (or <code class="option">-u</code>), and
      <code class="option">--password</code> (or <code class="option">-p</code>) options that
      specify connection parameters. They indicate the host where the
      MySQL server is running, and the username and password of your
      MySQL account. All MySQL client programs understand these options;
      they allow you to specify which server to connect to and the
      account to use on that server.
    </p><p>
      Other connection options are <code class="option">--port</code> (or
      <code class="option">-P</code>) to specify a TCP/IP port number and
      <code class="option">--socket</code> (or <code class="option">-S</code>) to specify a
      Unix socket file on Unix (or named pipe name on Windows).
    </p><p>
      The default hostname is <code class="literal">localhost</code>. For client
      programs on Unix, the hostname <code class="literal">localhost</code> is
      special. It causes the client to connect to the MySQL server
      through a Unix socket file. This occurs even if a
      <code class="option">--port</code> or <code class="option">-P</code> option is given to
      specify a port number. To ensure that the client makes a TCP/IP
      connection to the local server, use <code class="option">--host</code> or
      <code class="option">-h</code> to specify a hostname value of
      <code class="literal">127.0.0.1</code>, or the IP address or name of the
      local server. You can also specify the connection protocol
      explicitly, even for <code class="literal">localhost</code>, by using the
      <code class="option">--protocol=tcp</code> option.
    </p><p>
      On Windows, the hostname <code class="literal">.</code> causes the client to
      connect to the local server using a named pipe, if the server has
      named-pipe connections enabled. If named-pipe connections are not
      enabled, an error occurs.
    </p><a class="indexterm" name="id2549495"></a><a class="indexterm" name="id2549504"></a><p>
      You may find it necessary to invoke MySQL programs using the
      pathname to the <code class="filename">bin</code> directory in which they
      are installed. This is likely to be the case if you get a
      “<span class="quote">program not found</span>” error whenever you attempt to run
      a MySQL program from any directory other than the
      <code class="filename">bin</code> directory. To make it more convenient to
      use MySQL, you can add the pathname of the
      <code class="filename">bin</code> directory to your <code class="literal">PATH</code>
      environment variable setting. That enables you to run a program by
      typing only its name, not its entire pathname. For example, if
      <span><strong class="command">mysql</strong></span> is installed in
      <code class="filename">/usr/local/mysql/bin</code>, you'll be able to run
      it by invoking it as <span><strong class="command">mysql</strong></span>; it will not be
      necessary to invoke it as
      <span><strong class="command">/usr/local/mysql/bin/mysql</strong></span>.
    </p><p>
      Consult the documentation for your command interpreter for
      instructions on setting your <code class="literal">PATH</code> variable. The
      syntax for setting environment variables is interpreter-specific.
      (Some information is given in
      <a href="using-mysql-programs.html#setting-environment-variables" title="4.4. Setting Environment Variables">Section 4.4, “Setting Environment Variables”</a>.) 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><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="program-options"></a>4.3. Specifying Program Options</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="using-mysql-programs.html#command-line-options">4.3.1. Using Options on the Command Line</a></span></dt><dt><span class="section"><a href="using-mysql-programs.html#option-files">4.3.2. Using Option Files</a></span></dt><dt><span class="section"><a href="using-mysql-programs.html#program-variables">4.3.3. Using Options to Set Program Variables</a></span></dt></dl></div><p>
      There are several ways to specify options for MySQL programs:
    </p><div class="itemizedlist"><ul type="disc"><li><p>
          List the options on the command line following the program
          name. This is most common for options that apply to a specific
          invocation of the program.
        </p></li><li><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><p>
          List the options in environment variables (see
          <a href="using-mysql-programs.html#setting-environment-variables" title="4.4. Setting Environment Variables">Section 4.4, “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 href="server-administration.html#multiple-unix-servers" title="5.11.2. Running Multiple Servers on Unix">Section 5.11.2, “Running Multiple Servers 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>
      MySQL programs determine which options are given first by
      examining environment variables, then by reading option files, and
      then by checking the command line. This means that environment
      variables have the lowest precedence and command-line options the
      highest.
    </p><p>
      Because options are processed in order, if an option is specified
      multiple times, the last occurrence takes precedence. The
      following command causes <span><strong class="command">mysql</strong></span> to connect to
      the server running on <code class="literal">localhost</code>:
    </p><pre class="programlisting">shell&gt; <strong class="userinput"><code>mysql -h example.com -h localhost</code></strong>
</pre><p>
      If conflicting or related options are given, later options take
      precedence over earlier options. The following command runs
      <span><strong class="command">mysql</strong></span> in “<span class="quote">no column names</span>” mode:
    </p><pre class="programlisting">shell&gt; <strong class="userinput"><code>mysql --column-names --skip-column-names</code></strong>
</pre><p>
      An option can be specified by writing it in full or as any
      unambiguous prefix. For example, the <code class="option">--compress</code>
      option can be given to <span><strong class="command">mysqldump</strong></span> as
      <code class="option">--compr</code>, but not as <code class="option">--comp</code>
      because the latter is ambiguous:
    </p><pre class="programlisting">shell&gt; <strong class="userinput"><code>mysqldump --comp</code></strong>
mysqldump: ambiguous option '--comp' (compatible, compress)
</pre><p>
      Be aware that the use of option prefixes can cause problems in the
      event that new options are implemented for a program. A prefix
      that is unambigious now might become ambiguous in the future.
    </p><p>
      You can take advantage of the way that MySQL programs process
      options by specifying default values for a program's options in an
      option file. That enables you to avoid typing them each time you
      run the program, but also allows you to override the defaults if
      necessary by using command-line options.
    </p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="command-line-options"></a>4.3.1. Using Options on the Command Line</h3></div></div></div><div class="toc"><dl><dt><span class="section"><a href="using-mysql-programs.html#option-modifiers">4.3.1.1. Program Option Modifiers</a></span></dt></dl></div><p>
        Program options specified on the command line follow these
        rules:
      </p><div class="itemizedlist"><ul type="disc"><li><p>
            Options are given after the command name.
          </p></li><li><p>
            An option argument begins with one dash or two dashes,
            depending on whether it has a short name or a long name.
            Many options have both forms. For example,
            <code class="option">-?</code> and <code class="option">--help</code> are the
            short and long forms of the option that instructs a MySQL
            program to display its help message.
          </p></li><li><p>
            Option names are case sensitive. <code class="option">-v</code> and
            <code class="option">-V</code> are both legal and have different
            meanings. (They are the corresponding short forms of the
            <code class="option">--verbose</code> and <code class="option">--version</code>
            options.)
          </p></li><li><p>
            Some options take a value following the option name. For
            example, <code class="option">-h localhost</code> or
            <code class="option">--host=localhost</code> indicate the MySQL server
            host to a client program. The option value tells the program
            the name of the host where the MySQL server is running.
          </p></li><li><p>
            For a long option that takes a value, separate the option
            name and the value by an “<span class="quote"><code class="literal">=</code></span>”
            sign. For a short option that takes a value, the option
            value can immediately follow the option letter, or there can
            be a space between: <code class="option">-hlocalhost</code> and
            <code class="option">-h localhost</code> are equivalent. An exception
            to this rule is the option for specifying your MySQL
            password. This option can be given in long form as
            <code class="option">--password=<em class="replaceable"><code>pass_val</code></em></code>
            or as <code class="option">--password</code>. In the latter case (with
            no password value given), the program prompts you for the
            password. The password option also may be given in short
            form as
            <code class="option">-p<em class="replaceable"><code>pass_val</code></em></code> or as
            <code class="option">-p</code>. However, for the short form, if the
            password value is given, it must follow the option letter
            with <span class="emphasis"><em>no intervening space</em></span>. The reason
            for this is that if a space follows the option letter, the
            program has no way to tell whether a following argument is
            supposed to be the password value or some other kind of
            argument. Consequently, the following two commands have two
            completely different meanings:
          </p><pre class="programlisting">shell&gt; <strong class="userinput"><code>mysql -ptest</code></strong>
shell&gt; <strong class="userinput"><code>mysql -p test</code></strong>
</pre><p>
            The first command instructs <span><strong class="command">mysql</strong></span> to use
            a password value of <code class="literal">test</code>, but specifies
            no default database. The second instructs
            <span><strong class="command">mysql</strong></span> to prompt for the password value
            and to use <code class="literal">test</code> as the default database.
          </p></li></ul></div><p>
        Another option that may occasionally be useful with
        <span><strong class="command">mysql</strong></span> is the <code class="option">--execute</code> or
        <code class="option">-e</code> option, which can be used to pass SQL
        statements to the server. When this option is used,
        <span><strong class="command">mysql</strong></span> executes the statements and exits. The
        statements must be enclosed by quotation marks. For example, you
        can use the following command to obtain a list of user accounts:
      </p><pre class="programlisting">shell&gt; <strong class="userinput"><code>mysql -u root -p --execute="SELECT User, Host FROM user" mysql</code></strong>
Enter password: <strong class="userinput"><code>******</code></strong>
+------+-----------+
| User | Host      |
+------+-----------+
|      | gigan     |
| root | gigan     |
|      | localhost |
| jon  | localhost |
| root | localhost |
+------+-----------+
shell&gt;
</pre><p>
        Note that the long form (<code class="option">--execute</code>) is followed
        by an equals sign (<code class="literal">=</code>).
      </p><p>
        If you wish to use quoted values within a statement, you will
        either need to escape the inner quotes, or use a different type
        of quotes within the statement from those used to quote the
        statement itself. The capabilities of your command processor
        dictate your choices for whether you can use single or double
        quotation marks and the syntax for escaping quote characters.
        For example, if your command processor supports quoting with
        single or double quotes, you can double quotes around the
        statement, and single quotes for any quoted values within the
        statement.
      </p><p>
        In the preceding example, the name of the
        <code class="literal">mysql</code> database was passed as a separate
        argument. However, the same statement could have been executed
        using this command, which specifies no default database:
      </p><pre class="programlisting">mysql&gt; <strong class="userinput"><code>mysql -u root -p --execute="SELECT User, Host FROM mysql.user"</code></strong>
</pre><p>
        Multiple SQL statements may be passed on the command line,
        separated by semicolons:
      </p><pre class="programlisting">shell&gt; <strong class="userinput"><code>mysql -u root -p -e "SELECT VERSION();SELECT NOW()"</code></strong>
Enter password: <strong class="userinput"><code>******</code></strong>
+------------+
| VERSION()  |
+------------+
| 5.0.19-log |
+------------+
+---------------------+
| NOW()               |
+---------------------+
| 2006-01-05 21:19:04 |
+---------------------+
</pre><p>
        The <code class="option">--execute</code> or <code class="option">-e</code> option may
        also be used to pass commands in an analogous fashion to the
        <span><strong class="command">ndb_mgm</strong></span> management client for MySQL Cluster.
        See <a href="mysql-cluster.html#mysql-cluster-multi-shutdown-restart" title="16.2.6. Safe Shutdown and Restart">Section 16.2.6, “Safe Shutdown and Restart”</a>, for
        an example.
      </p><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="option-modifiers"></a>4.3.1.1. Program Option Modifiers</h4></div></div></div><a class="indexterm" name="id2550155"></a><p>
          Some options control behavior that can be turned on or off.
          For example, the <span><strong class="command">mysql</strong></span> client supports a
          <code class="option">--column-names</code> option that determines whether
          or not to display a row of column names at the beginning of
          query results. By default, this option is enabled. However,
          you may want to disable it in some instances, such as when
          sending the output of <span><strong class="command">mysql</strong></span> into another
          program that expects to see only data and not an initial
          header line.
        </p><p>
          To disable column names, you can specify the option using any
          of these forms:
        </p><pre class="programlisting">--disable-column-names
--skip-column-names
--column-names=0
</pre><p>
          The <code class="option">--disable</code> and <code class="option">--skip</code>
          prefixes and the <code class="literal">=0</code> suffix all have the
          same effect: They turn the option off.
        </p><p>
          The “<span class="quote">enabled</span>” form of the option may be specified
          in any of these ways:
        </p><pre class="programlisting">--column-names
--enable-column-names
--column-names=1
</pre><p>
          If an option is prefixed by <code class="option">--loose</code>, a
          program does not exit with an error if it does not recognize
          the option, but instead issues only a warning:
        </p><pre class="programlisting">shell&gt; <strong class="userinput"><code>mysql --loose-no-such-option</code></strong>
mysql: WARNING: unknown option '--no-such-option'
</pre><p>
          The <code class="option">--loose</code> prefix can be useful when you run
          programs from multiple installations of MySQL on the same
          machine and list options in an option file, An option that may
          not be recognized by all versions of a program can be given
          using the <code class="option">--loose</code> prefix (or
          <code class="literal">loose</code> in an option file). Versions of the
          program that recognize the option process it normally, and
          versions that do not recognize it issue a warning and ignore
          it.
        </p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="option-files"></a>4.3.2. Using Option Files</h3></div></div></div><div class="toc"><dl><dt><span class="section"><a href="using-mysql-programs.html#option-file-options">4.3.2.1. Command-Line Options that Affect Option-File Handling</a></span></dt><dt><span class="section"><a href="using-mysql-programs.html#option-files-preconfigured">4.3.2.2. Preconfigured Option Files</a></span></dt></dl></div><a class="indexterm" name="id2550295"></a><a class="indexterm" name="id2550304"></a><a class="indexterm" name="id2550313"></a><a class="indexterm" name="id2550326"></a><a class="indexterm" name="id2550339"></a><p>
        Most MySQL programs can read startup options from option files
        (also sometimes called configuration files). Option files
        provide a convenient way to specify commonly used options so
        that they need not be entered on the command line each time you
        run a program. For the MySQL server, MySQL provides a number of
        <a href="using-mysql-programs.html#option-files-preconfigured" title="4.3.2.2. Preconfigured Option Files">preconfigured option
        files</a>.
      </p><p>
        To determine whether a program reads option files, invoke it
        with the <code class="option">--help</code> option. (For
        <span><strong class="command">mysqld</strong></span>, use <code class="option">--verbose</code> and
        <code class="option">--help</code>.) If the program reads option files, the
        help message indicates which files it looks for and which option
        groups it recognizes.
      </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
          Option files used with MySQL Cluster programs are covered in
          <a href="mysql-cluster.html#mysql-cluster-configuration" title="16.3. MySQL Cluster Configuration">Section 16.3, “MySQL Cluster Configuration”</a>.
        </p></div><p>
        On Windows, MySQL programs read startup options from the
        following files:
      </p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><tbody><tr><td><span class="bold"><strong>Filename</strong></span></td><td><span class="bold"><strong>Purpose</strong></span></td></tr><tr><td><code class="filename"><em class="replaceable"><code>WINDIR</code></em>\my.ini</code>,
                <code class="filename"><em class="replaceable"><code>WINDIR</code></em>\my.cnf</code></td><td>Global options</td></tr><tr><td><code class="filename">C:\my.ini</code>, <code class="filename">C:\my.cnf</code></td><td>Global options</td></tr><tr><td><code class="filename"><em class="replaceable"><code>INSTALLDIR</code></em>\my.ini</code>,
                <code class="filename"><em class="replaceable"><code>INSTALLDIR</code></em>\my.cnf</code></td><td>Global Options</td></tr><tr><td><code class="literal">defaults-extra-file</code></td><td>The file specified with
                <code class="option">--defaults-extra-file=<em class="replaceable"><code>path</code></em></code>,
                if any</td></tr></tbody></table></div><p>
        <em class="replaceable"><code>WINDIR</code></em> represents the location of
        your Windows directory. This is commonly
        <code class="filename">C:\WINDOWS</code>. You can determine its exact
        location from the value of the <code class="filename">WINDIR</code>
        environment variable using the following command:
      </p><pre class="programlisting">C:\&gt; <strong class="userinput"><code>echo %WINDIR%</code></strong>
</pre><p>
        <em class="replaceable"><code>INSTALLDIR</code></em> represents the MySQL
        installation directory. This is typically
        <code class="filename">C:\<em class="replaceable"><code>PROGRAMDIR</code></em>\MySQL\MySQL
        5.0 Server</code> where
        <em class="replaceable"><code>PROGRAMDIR</code></em> represents the programs
        directory (usually <code class="filename">Program Files</code> on
        English-language versions of Windows), when MySQL
        5.0 has been installed using the installation and
        configuration wizards. See
        <a href="installing.html#mysql-config-wizard-starting-windows" title="2.4.8.4.1.1. The MySQL Server Configuration Wizard on Windows">Section 2.4.8.4.1.1, “The MySQL Server Configuration Wizard on Windows”</a>.
      </p><p>
        On Unix, MySQL programs read startup options from the following
        files:
      </p><a class="indexterm" name="id2550608"></a><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><tbody><tr><td><span class="bold"><strong>Filename</strong></span></td><td><span class="bold"><strong>Purpose</strong></span></td></tr><tr><td><code class="filename">/etc/my.cnf</code></td><td>Global options</td></tr><tr><td><code class="filename"><em class="replaceable"><code>SYSCONFDIR</code></em>/my.cnf</code></td><td>Global Options</td></tr><tr><td><code class="filename">$MYSQL_HOME/my.cnf</code></td><td>Server-specific options</td></tr><tr><td><code class="literal">defaults-extra-file</code></td><td>The file specified with
                <code class="option">--defaults-extra-file=<em class="replaceable"><code>path</code></em></code>,
                if any</td></tr><tr><td><code class="filename">~/.my.cnf</code></td><td>User-specific options</td></tr></tbody></table></div><p>
        <em class="replaceable"><code>SYSCONFDIR</code></em> represents the directory
        specified with the <code class="literal">--sysconfdir</code> option to
        <span><strong class="command">configure</strong></span> when MySQL was built. By default,
        this is the <code class="filename">etc</code> directory located under the
        compiled-in installation directory. This location is used as of
        MySQL 5.0.21. (From 5.0.21 to 5.0.53, it was read last, after
        <code class="filename">~/.my.cnf</code>.)
      </p><p>
        <code class="literal">MYSQL_HOME</code> is an environment variable
        containing the path to the directory in which the
        server-specific <code class="filename">my.cnf</code> file resides. (This
        was <em class="replaceable"><code>DATADIR</code></em> prior to MySQL version
        5.0.3.)
      </p><p>
        If <code class="literal">MYSQL_HOME</code> is not set and you start the
        server using the <span><strong class="command">mysqld_safe</strong></span> program,
        <span><strong class="command">mysqld_safe</strong></span> attempts to set
        <code class="literal">MYSQL_HOME</code> as follows:
      </p><div class="itemizedlist"><ul type="disc"><li><p>
            Let <em class="replaceable"><code>BASEDIR</code></em> and
            <em class="replaceable"><code>DATADIR</code></em> represent the pathnames
            of the MySQL base directory and data directory,
            respectively.
          </p></li><li><p>
            If there is a <code class="filename">my.cnf</code> file in
            <em class="replaceable"><code>DATADIR</code></em> but not in
            <em class="replaceable"><code>BASEDIR</code></em>,
            <span><strong class="command">mysqld_safe</strong></span> sets
            <code class="literal">MYSQL_HOME</code> to
            <em class="replaceable"><code>DATADIR</code></em>.
          </p></li><li><p>
            Otherwise, if <code class="literal">MYSQL_HOME</code> is not set and
            there is no <code class="filename">my.cnf</code> file in
            <em class="replaceable"><code>DATADIR</code></em>,
            <span><strong class="command">mysqld_safe</strong></span> sets
            <code class="literal">MYSQL_HOME</code> to
            <em class="replaceable"><code>BASEDIR</code></em>.
          </p></li></ul></div><p>
        In MySQL 5.0, use of
        <em class="replaceable"><code>DATADIR</code></em> as the location for
        <code class="filename">my.cnf</code> is deprecated.
      </p><p>
        Typically, <em class="replaceable"><code>DATADIR</code></em> is
        <code class="filename">/usr/local/mysql/data</code> for a binary
        installation or <code class="filename">/usr/local/var</code> for a source
        installation. Note that this is the data directory location that
        was specified at configuration time, not the one specified with
        the <code class="option">--datadir</code> option when
        <span><strong class="command">mysqld</strong></span> starts. Use of
        <code class="option">--datadir</code> at runtime has no effect on where the
        server looks for option files, because it looks for them before
        processing any options.
      </p><p>
        MySQL looks for option files in the order just described and
        reads any that exist. If an option file that you want to use
        does not exist, create it with a plain text editor.
      </p><p>
        If multiple instances of a given option are found, the last
        instance takes precedence. There is one exception: For
        <span><strong class="command">mysqld</strong></span>, the <span class="emphasis"><em>first</em></span>
        instance of the <code class="option">--user</code> option is used as a
        security precaution, to prevent a user specified in an option
        file from being overridden on the command line.
      </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
          On Unix platforms, MySQL ignores configuration files that are
          world-writable. This is intentional as a security measure.
        </p></div><p>
        Any long option that may be given on the command line when
        running a MySQL program can be given in an option file as well.
        To get the list of available options for a program, run it with
        the <code class="option">--help</code> option.
      </p><p>
        The syntax for specifying options in an option file is similar
        to command-line syntax, except that you omit the leading two
        dashes. For example, <code class="option">--quick</code> or
        <code class="option">--host=localhost</code> on the command line should be
        specified as <code class="literal">quick</code> or
        <code class="literal">host=localhost</code> in an option file. To specify
        an option of the form
        <code class="option">--loose-<em class="replaceable"><code>opt_name</code></em></code> in
        an option file, write it as
        <code class="literal">loose-<em class="replaceable"><code>opt_name</code></em></code>.
      </p><p>
        Empty lines in option files are ignored. Non-empty lines can
        take any of the following forms:
      </p><div class="itemizedlist"><ul type="disc"><li><p>
            <code class="literal">#<em class="replaceable"><code>comment</code></em></code>,
            <code class="literal">;<em class="replaceable"><code>comment</code></em></code>
          </p><p>
            Comment lines start with “<span class="quote"><code class="literal">#</code></span>”
            or “<span class="quote"><code class="literal">;</code></span>”. A
            “<span class="quote"><code class="literal">#</code></span>” comment can start in the
            middle of a line as well.
          </p></li><li><p>
            <code class="literal">[<em class="replaceable"><code>group</code></em>]</code>
          </p><p>
            <em class="replaceable"><code>group</code></em> is the name of the program
            or group for which you want to set options. After a group
            line, any option-setting lines apply to the named group
            until the end of the option file or another group line is
            given.
          </p></li><li><p>
            <code class="literal"><em class="replaceable"><code>opt_name</code></em></code>
          </p><p>
            This is equivalent to
            <code class="option">--<em class="replaceable"><code>opt_name</code></em></code> on
            the command line.
          </p></li><li><p>
            <code class="literal"><em class="replaceable"><code>opt_name</code></em>=<em class="replaceable"><code>value</code></em></code>
          </p><p>
            This is equivalent to
            <code class="option">--<em class="replaceable"><code>opt_name</code></em>=<em class="replaceable"><code>value</code></em></code>
            on the command line. In an option file, you can have spaces
            around the “<span class="quote"><code class="literal">=</code></span>” character,
            something that is not true on the command line. You can
            enclose the value within single quotes or double quotes,
            which is useful if the value contains a
            “<span class="quote"><code class="literal">#</code></span>” comment character or
            whitespace.
          </p></li></ul></div><p>
        For options that take a numeric value, the value can be given
        with a suffix of <code class="literal">K</code>, <code class="literal">M</code>, or
        <code class="literal">G</code> (either uppercase or lowercase) to indicate
        a multiplier of 1024, 1024<sup>2</sup> or
        1024<sup>3</sup>. For example, the following
        command tells <span><strong class="command">mysqladmin</strong></span> to ping the server
        1024 times, sleeping 10 seconds between each ping:
      </p><pre class="programlisting">mysql&gt; <strong class="userinput"><code>mysqladmin --count=1K --sleep=10 ping</code></strong>
</pre><p>
        Leading and trailing blanks are automatically deleted from
        option names and values. You may use the escape sequences
        “<span class="quote"><code class="literal">\b</code></span>”,
        “<span class="quote"><code class="literal">\t</code></span>”,
        “<span class="quote"><code class="literal">\n</code></span>”,
        “<span class="quote"><code class="literal">\r</code></span>”,
        “<span class="quote"><code class="literal">\\</code></span>”, and
        “<span class="quote"><code class="literal">\s</code></span>” in option values to
        represent the backspace, tab, newline, carriage return,
        backslash, and space characters.
      </p><p>
        Because the “<span class="quote"><code class="literal">\\</code></span>” escape sequence
        represents a single backslash, you must write each
        “<span class="quote"><code class="literal">\</code></span>” as
        “<span class="quote"><code class="literal">\\</code></span>”. Alternatively, you can
        specify the value using “<span class="quote"><code class="literal">/</code></span>”
        rather than “<span class="quote"><code class="literal">\</code></span>” as the pathname
        separator.
      </p><p>
        If an option group name is the same as a program name, options
        in the group apply specifically to that program. For example,
        the <code class="literal">[mysqld]</code> and <code class="literal">[mysql]</code>
        groups apply to the <span><strong class="command">mysqld</strong></span> server and the
        <span><strong class="command">mysql</strong></span> client program, respectively.
      </p><p>
        The <code class="literal">[client]</code> option group is read by all
        client programs (but <span class="emphasis"><em>not</em></span> by
        <span><strong class="command">mysqld</strong></span>). This allows you to specify options
        that apply to all clients. For example,
        <code class="literal">[client]</code> is the perfect group to use to
        specify the password that you use to connect to the server. (But
        make sure that the option file is readable and writable only by
        yourself, so that other people cannot find out your password.)
        Be sure not to put an option in the <code class="literal">[client]</code>
        group unless it is recognized by <span class="emphasis"><em>all</em></span> client
        programs that you use. Programs that do not understand the
        option quit after displaying an error message if you try to run
        them.
      </p><p>
        Here is a typical global option file:
      </p><pre class="programlisting">[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M

[mysqldump]
quick
</pre><p>
        The preceding option file uses
        <code class="literal"><em class="replaceable"><code>var_name</code></em>=<em class="replaceable"><code>value</code></em></code>
        syntax for the lines that set the
        <code class="literal">key_buffer_size</code> and
        <code class="literal">max_allowed_packet</code> variables.
      </p><p>
        Here is a typical user option file:
      </p><pre class="programlisting">[client]
# The following password will be sent to all standard MySQL clients
password="my_password"

[mysql]
no-auto-rehash
connect_timeout=2

[mysqlhotcopy]
interactive-timeout
</pre><p>
        If you want to create option groups that should be read by
        <span><strong class="command">mysqld</strong></span> servers from a specific MySQL release
        series only, you can do this by using groups with names of
        <code class="literal">[mysqld-4.1]</code>,
        <code class="literal">[mysqld-5.0]</code>, and so forth. The
        following group indicates that the <code class="option">--new</code> option
        should be used only by MySQL servers with 5.0.x
        version numbers:
      </p><pre class="programlisting">[mysqld-5.0]
new
</pre><p>
        In shell scripts, you can use the
        <span><strong class="command">my_print_defaults</strong></span> program to parse option
        files and see what options would be used by a given program. The
        following example shows the output that
        <span><strong class="command">my_print_defaults</strong></span> might produce when asked to
        show the options found in the <code class="literal">[client]</code> and
        <code class="literal">[mysql]</code> groups:
      </p><pre class="programlisting">shell&gt; <strong class="userinput"><code>my_print_defaults client mysql</code></strong>
--port=3306
--socket=/tmp/mysql.sock
--no-auto-rehash
</pre><p>
        <span class="bold"><strong>Note for developers</strong></span>: Option
        file handling is implemented in the C client library simply by
        processing all options in the appropriate group or groups before
        any command-line arguments. This works well for programs that
        use the last instance of an option that is specified multiple
        times. If you have a C or C++ program that handles multiply
        specified options this way but that doesn't read option files,
        you need add only two lines to give it that capability. Check
        the source code of any of the standard MySQL clients to see how
        to do this.
      </p><p>
        Several other language interfaces to MySQL are based on the C
        client library, and some of them provide a way to access option
        file contents. These include Perl and Python. For details, see
        the documentation for your preferred interface.
      </p><p>
        Beginning with MySQL 5.0.4, it is possible to use
        <code class="literal">!include</code> directives in option files to
        include other option files and <code class="literal">!includedir</code> to
        search specific directories for option files. For example, to
        include the <code class="filename">/home/mydir/myopt.cnf</code> file, use
        the following directive:
      </p><pre class="programlisting">!include /home/mydir/myopt.cnf
</pre><p>
        To search the <code class="filename">/home/mydir</code> directory and
        read option files found there, use this directive:
      </p><pre class="programlisting">!includedir /home/mydir
</pre><p>
        There is no guarantee about the order in which the option files
        in the directory will be read.
      </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
          Currently, any files to be found and included using the
          <code class="literal">!includedir</code> directive on Unix operating
          systems <span class="emphasis"><em>must</em></span> have filenames ending in
          <code class="filename">.cnf</code>. On Windows, this directive checks
          for files with the <code class="filename">.ini</code> or
          <code class="filename">.cnf</code> extension.
        </p></div><p>
        Write the contents of an included option file like any other
        option file. That is, it should contain groups of options, each
        preceded by a
        <code class="literal">[<em class="replaceable"><code>group</code></em>]</code> line that
        indicates the program to which the options apply.
      </p><p>
        While an included file is being processed, only those options in
        groups that the current program is looking for are used. Other
        groups are ignored. Suppose that a <code class="filename">my.cnf</code>
        file contains this line:
      </p><pre class="programlisting">!include /home/mydir/myopt.cnf
</pre><p>
        And suppose that <code class="filename">/home/mydir/myopt.cnf</code>
        looks like this:
      </p><pre class="programlisting">[mysqladmin]
force

[mysqld]
key_buffer_size=16M
</pre><p>
        If <code class="filename">my.cnf</code> is processed by
        <span><strong class="command">mysqld</strong></span>, only the <code class="literal">[mysqld]</code>
        group in <code class="filename">/home/mydir/myopt.cnf</code> is used. If
        the file is processed by <span><strong class="command">mysqladmin</strong></span>, only the
        <code class="literal">[mysqldamin]</code> group is used. If the file is
        processed by any other program, no options in
        <code class="filename">/home/mydir/myopt.cnf</code> are used.
      </p><p>
        The <code class="literal">!includedir</code> directive is processed
        similarly except that all option files in the named directory
        are read.
      </p><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="option-file-options"></a>4.3.2.1. Command-Line Options that Affect Option-File Handling</h4></div></div></div><p>
          Most MySQL programs that support option files handle the
          following options. They affect option-file handling, so they
          must be given on the command line and not in an option file.
          To work properly, each of these options must immediately
          follow the command name, with the exception that
          <code class="option">--print-defaults</code> may be used immediately
          after <code class="option">--defaults-file</code> or
          <code class="option">--defaults-extra-file</code>. Also, when specifying
          filenames, you should avoid the use of the
          “<span class="quote"><code class="literal">~</code></span>” shell metacharacter
          because it might not be interpreted as you expect.
        </p><div class="itemizedlist"><ul type="disc"><li><p><a name="option_no-defaults"></a>
              <a class="indexterm" name="id2551856"></a>

              <code class="option">--no-defaults</code>
            </p><p>
              Don't read any option files.
            </p></li><li><p><a name="option_print-defaults"></a>
              <a class="indexterm" name="id2551882"></a>

              <code class="option">--print-defaults</code>
            </p><p>
              Print the program name and all options that it gets from
              option files.
            </p></li><li><p><a name="option_defaults-file"></a>
              <a class="indexterm" name="id2551909"></a>

              <code class="option">--defaults-file=<em class="replaceable"><code>file_name</code></em></code>
            </p><p>
              Use only the given option file.
              <em class="replaceable"><code>file_name</code></em> is the full pathname
              to the file. If the file does not exist or is otherwise
              inaccessible, the program will exit with an error.
            </p></li><li><p><a name="option_defaults-extra-file"></a>
              <a class="indexterm" name="id2551944"></a>

              <code class="option">--defaults-extra-file=<em class="replaceable"><code>file_name</code></em></code>
            </p><p>
              Read this option file after the global option file but (on
              Unix) before the user option file.
              <em class="replaceable"><code>file_name</code></em> is the full pathname
              to the file. As of MySQL 5.0.6, if the file does not exist
              or is otherwise inaccessible, the program will exit with
              an error.
            </p></li><li><p><a name="option_defaults-group-suffix"></a>
              <a class="indexterm" name="id2551981"></a>

              <code class="option">--defaults-group-suffix=<em class="replaceable"><code>str</code></em></code>
            </p><p>
              If this option is given, the program reads not only its
              usual option groups, but also groups with the usual names
              and a suffix of <em class="replaceable"><code>str</code></em>. For
              example, the <span><strong class="command">mysql</strong></span> client normally
              reads the <code class="literal">[client]</code> and
              <code class="literal">[mysql]</code> groups. If the
              <code class="option">--default-group-suffix=_other</code> option is
              given, <span><strong class="command">mysql</strong></span> also reads the
              <code class="literal">[client_other]</code> and
              <code class="literal">[mysql_other]</code> groups. This option was
              added in MySQL 5.0.10.
            </p></li></ul></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="option-files-preconfigured"></a>4.3.2.2. Preconfigured Option Files</h4></div></div></div><p>
          MySQL provides a number of preconfigured option files that can
          be used as a basis for tuning the MySQL server. Look for files
          such as <code class="filename">my-small.cnf</code>,
          <code class="filename">my-medium.cnf</code>,
          <code class="filename">my-large.cnf</code>, and
          <code class="filename">my-huge.cnf</code>, which are sample option
          files for small, medium, large, and very large systems. On
          Windows, the extension is <code class="filename">.ini</code> rather
          than <code class="filename">.cnf</code> extension.
        </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
            On Windows, the <code class="filename">.cnf</code> or
            <code class="filename">.ini</code> option file extension might not be
            displayed.
          </p></div><p>
          For a binary distribution, look for the files in or under your
          installation directory. If you have a source distribution,
          look in the <code class="filename">support-files</code> directory. You
          can rename a copy of a sample file and place it in the
          appropriate location for use as a base configuration file.
          Regarding names and appropriate location, see the general
          information provided in <a href="using-mysql-programs.html#option-files" title="4.3.2. Using Option Files">Section 4.3.2, “Using Option Files”</a>.
        </p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="program-variables"></a>4.3.3. Using Options to Set Program Variables</h3></div></div></div><a class="indexterm" name="id2552160"></a><a class="indexterm" name="id2552172"></a><p>
        Many MySQL programs have internal variables that can be set at
        runtime. Program variables are set the same way as any other
        long option that takes a value. For example,
        <span><strong class="command">mysql</strong></span> has a
        <code class="literal">max_allowed_packet</code> variable that controls the
        maximum size of its communication buffer. To set the
        <code class="literal">max_allowed_packet</code> variable for
        <span><strong class="command">mysql</strong></span> to a value of 16MB, use either of the
        following commands:
      </p><pre class="programlisting">shell&gt; <strong class="userinput"><code>mysql --max_allowed_packet=16777216</code></strong>
shell&gt; <strong class="userinput"><code>mysql --max_allowed_packet=16M</code></strong>
</pre><p>
        The first command specifies the value in bytes. The second
        specifies the value in megabytes. For variables that take a
        numeric value, the value can be given with a suffix of
        <code class="literal">K</code>, <code class="literal">M</code>, or
        <code class="literal">G</code> (either uppercase or lowercase) to indicate
        a multiplier of 1024, 1024<sup>2</sup> or
        1024<sup>3</sup>. (For example, when used to set
        <code class="literal">max_allowed_packet</code>, the suffixes indicate
        units of kilobytes, megabytes, or gigabytes.)
      </p><p>
        In an option file, variable settings are given without the
        leading dashes:
      </p><pre class="programlisting">[mysql]
max_allowed_packet=16777216
</pre><p>
        Or:
      </p><pre class="programlisting">[mysql]
max_allowed_packet=16M
</pre><p>
        If you like, underscores in a variable name can be specified as
        dashes. The following option groups are equivalent. Both set the
        size of the server's key buffer to 512MB:
      </p><pre class="programlisting">[mysqld]
key_buffer_size=512M

[mysqld]
key-buffer-size=512M
</pre><p>
        A variable can be specified by writing it in full or as any
        unambiguous prefix. For example, the
        <code class="literal">max_buffer_length</code> variable can be set for
        <span><strong class="command">mysql</strong></span> as <code class="option">--max_a</code>, but not as
        <code class="option">--max</code> because the latter is ambiguous:
      </p><pre class="programlisting">shell&gt; <strong class="userinput"><code>mysql --max=1000000</code></strong>
mysql: ambiguous option '--max=1000000' (max_allowed_packet, max_join_size)
</pre><p>
        Be aware that the use of variable prefixes can cause problems in
        the event that new variables are implemented for a program. A
        prefix that is unambigious now might become ambiguous in the
        future.
      </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
          Before MySQL 4.0.2, the only syntax for setting program
          variables was
          <code class="option">--set-variable=<em class="replaceable"><code>option</code></em>=<em class="replaceable"><code>value</code></em></code>
          (or
          <code class="option">set-variable=<em class="replaceable"><code>option</code></em>=<em class="replaceable"><code>value</code></em></code>
          in option files). Underscores cannot be given as dashes, and
          the variable name must be specified in full. This syntax still
          is recognized, but is now deprecated.
        </p></div><p>
        Many server system variables can also be set at runtime. For
        details, see <a href="server-administration.html#dynamic-system-variables" title="5.2.4.2. Dynamic System Variables">Section 5.2.4.2, “Dynamic System Variables”</a>.
      </p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="setting-environment-variables"></a>4.4. Setting Environment Variables</h2></div></div></div><a class="indexterm" name="id2552407"></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 href="installing.html#environment-variables" title="2.4.20. Environment Variables">Section 2.4.20, “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 or
      NetWare, you can set the <code class="literal">USER</code> variable to
      specify your MySQL account name. To do so, use this syntax:
    </p><pre class="programlisting">SET USER=<em class="replaceable"><code>your_name</code></em>
</pre><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><strong class="command">sh</strong></span>, <code class="literal">bash</code>,
      <span><strong class="command">zsh</strong></span>, and so on) is as follows:
    </p><pre class="programlisting">MYSQL_TCP_PORT=3306
export MYSQL_TCP_PORT
</pre><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><strong class="command">csh</strong></span> and <span><strong class="command">tcsh</strong></span>, use
      <span><strong class="command">setenv</strong></span> to make the shell variable available to
      the environment:
    </p><pre class="programlisting">setenv MYSQL_TCP_PORT 3306
</pre><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><strong class="command">bash</strong></span>, or <code class="filename">.tcshrc</code> for
      <span><strong class="command">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><strong class="command">bash</strong></span>,
      add the following line to your <code class="filename">.bashrc</code> file:
    </p><pre class="programlisting">PATH=${PATH}:/usr/local/mysql/bin
</pre><p>
      <span><strong class="command">bash</strong></span> uses different startup files for login and
      non-login 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 non-login shells to make
      sure that <code class="literal">PATH</code> is set regardless.
    </p><p>
      If your shell is <span><strong class="command">tcsh</strong></span>, add the following line
      to your <code class="filename">.tcshrc</code> file:
    </p><pre class="programlisting">setenv PATH ${PATH}:/usr/local/mysql/bin
</pre><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></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tutorial.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="server-administration.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 3. Tutorial </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 5. MySQL Server Administration</td></tr></table></div></body></html>