<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="changing-mysql-user">
      </a>
      8.1.5 How to Run MySQL as a Normal User
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045252618832">
  </a>
  <a class="indexterm" name="idm46045252617376">
  </a>
  <p>
   On Windows, you can run the server as a Windows service using a
      normal user account.
  </p>
  <p>
   On Linux, for installations performed using a MySQL repository or
      RPM packages, the MySQL server
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   should be
      started by the local
   <code class="literal">
    mysql
   </code>
   operating system
      user. Starting by another operating system user is not supported
      by the init scripts that are included as part of the MySQL
      repositories.
  </p>
  <p>
   On Unix (or Linux for installations performed using
   <code class="filename">
    tar.gz
   </code>
   packages) , the MySQL server
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   can be started and run by any user.
      However, you should avoid running the server as the Unix
   <code class="literal">
    root
   </code>
   user for security reasons. To change
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   to run as a normal unprivileged Unix
      user
   <em class="replaceable">
    <code>
     user_name
    </code>
   </em>
   , you must do the
      following:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Stop the server if it is running (use
      <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
       <span class="command">
        <strong>
         mysqladmin
          shutdown
        </strong>
       </span>
      </a>
      ).
     </p>
    </li>
    <li class="listitem">
     <p>
      Change the database directories and files so that
      <em class="replaceable">
       <code>
        user_name
       </code>
      </em>
      has privileges to read
          and write files in them (you might need to do this as the Unix
      <code class="literal">
       root
      </code>
      user):
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa10721238"><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">chown</span> <span class="token property">-R</span> <em class="replaceable">user_name</em> <em class="replaceable">/path/to/mysql/datadir</em></code></pre>
     </div>
     <p>
      If you do not do this, the server cannot access databases or
          tables when it runs as
      <em class="replaceable">
       <code>
        user_name
       </code>
      </em>
      .
     </p>
     <p>
      If directories or files within the MySQL data directory are
          symbolic links,
      <code class="literal">
       chown -R
      </code>
      might not follow
          symbolic links for you. If it does not, you must also follow
          those links and change the directories and files they point
          to.
     </p>
    </li>
    <li class="listitem">
     <p>
      Start the server as user
      <em class="replaceable">
       <code>
        user_name
       </code>
      </em>
      .
          Another alternative is to start
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      as
          the Unix
      <code class="literal">
       root
      </code>
      user and use the
      <a class="link" href="server-options.html#option_mysqld_user">
       <code class="option">
        --user=
        <em class="replaceable">
         <code>
          user_name
         </code>
        </em>
       </code>
      </a>
      option.
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      starts, then switches to run
          as the Unix user
      <em class="replaceable">
       <code>
        user_name
       </code>
      </em>
      before
          accepting any connections.
     </p>
    </li>
    <li class="listitem">
     <p>
      To start the server as the given user automatically at system
          startup time, specify the user name by adding a
      <code class="literal">
       user
      </code>
      option to the
      <code class="literal">
       [mysqld]
      </code>
      group of the
      <code class="filename">
       /etc/my.cnf
      </code>
      option file or the
      <code class="filename">
       my.cnf
      </code>
      option file in the server's data
          directory. For example:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa14263860"><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">user</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">user_name</em></span></code></pre>
     </div>
    </li>
   </ol>
  </div>
  <p>
   If your Unix machine itself is not secured, you should assign
      passwords to the MySQL
   <code class="literal">
    root
   </code>
   account in the
      grant tables. Otherwise, any user with a login account on that
      machine can run the
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   client with a
   <a class="link" href="mysql-command-options.html#option_mysql_user">
    <code class="option">
     --user=root
    </code>
   </a>
   option and perform any
      operation. (It is a good idea to assign passwords to MySQL
      accounts in any case, but especially so when other login accounts
      exist on the server host.) See
   <a class="xref" href="default-privileges.html" title="2.9.4 Securing the Initial MySQL Account">
    Section 2.9.4, “Securing the Initial MySQL Account”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
