<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="resetting-permissions">
      </a>
      B.3.3.2 How to Reset the Root Password
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045054083840">
  </a>
  <a class="indexterm" name="idm46045054082384">
  </a>
  <a class="indexterm" name="idm46045054080896">
  </a>
  <a class="indexterm" name="idm46045054079408">
  </a>
  <p>
   If you have never assigned a
   <code class="literal">
    root
   </code>
   password
          for MySQL, the server does not require a password at all for
          connecting as
   <code class="literal">
    root
   </code>
   . However, this is
          insecure. For instructions on assigning a password, 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>
  <p>
   If you know the
   <code class="literal">
    root
   </code>
   password and want to
          change it, see
   <a class="xref" href="alter-user.html" title="15.7.1.1 ALTER USER Statement">
    Section 15.7.1.1, “ALTER USER Statement”
   </a>
   , and
   <a class="xref" href="set-password.html" title="15.7.1.10 SET PASSWORD Statement">
    Section 15.7.1.10, “SET PASSWORD Statement”
   </a>
   .
  </p>
  <p>
   If you assigned a
   <code class="literal">
    root
   </code>
   password previously
          but have forgotten it, you can assign a new password. The
          following sections provide instructions for Windows and Unix
          and Unix-like systems, as well as generic instructions that
          apply to any system.
  </p>
  <div class="section">
   <div class="titlepage">
    <div>
     <div>
      <h5 class="title">
       <a name="resetting-permissions-windows">
       </a>
       B.3.3.2.1 Resetting the Root Password: Windows Systems
      </h5>
     </div>
    </div>
   </div>
   <p>
    On Windows, use the following procedure to reset the
            password for the MySQL
    <code class="literal">
     'root'@'localhost'
    </code>
    account. To change the password for a
    <code class="literal">
     root
    </code>
    account with a different host name
            part, modify the instructions to use that host name.
   </p>
   <div class="orderedlist">
    <ol class="orderedlist" type="1">
     <li class="listitem">
      <p>
       Log on to your system as Administrator.
      </p>
     </li>
     <li class="listitem">
      <p>
       Stop the MySQL server if it is running. For a server
                that is running as a Windows service, go to the Services
                manager: From the
       <span class="guimenu">
        Start
       </span>
       menu, select
       <span class="guisubmenu">
        Control Panel
       </span>
       , then
       <span class="guisubmenu">
        Administrative Tools
       </span>
       , then
       <span class="guimenuitem">
        Services
       </span>
       . Find the MySQL
                service in the list and stop it.
      </p>
      <p>
       If your server is not running as a service, you may need
                to use the Task Manager to force it to stop.
      </p>
     </li>
     <li class="listitem">
      <p>
       Create a text file containing the password-assignment
                statement on a single line. Replace the password with
                the password that you want to use.
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa93732034"><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-sql"><span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'root'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'MyNewPass'</span><span class="token punctuation">;</span></code></pre>
      </div>
     </li>
     <li class="listitem">
      <p>
       Save the file. This example assumes that you name the
                file
       <code class="filename">
        C:\mysql-init.txt
       </code>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       Open a console window to get to the command prompt: From
                the
       <span class="guimenu">
        Start
       </span>
       menu, select
       <span class="guisubmenu">
        Run
       </span>
       , then enter
       <span class="command">
        <strong>
         cmd
        </strong>
       </span>
       as the command to be run.
      </p>
     </li>
     <li class="listitem">
      <p>
       Start the MySQL server with the
       <a class="link" href="server-system-variables.html#sysvar_init_file">
        <code class="literal">
         init_file
        </code>
       </a>
       system
                variable set to name the file (notice that the backslash
                in the option value is doubled):
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa8963680"><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">C:\&gt;</span><span class="token command"> cd</span> <span class="token atrule">"C:\Program Files\MySQL\MySQL Server 8.4\bin"</span>
<span class="token prompt">C:\&gt;</span><span class="token command"> mysqld</span> <span class="token constant">--init-file</span><span class="token attr-value"><span class="token punctuation">=</span>C:\\mysql-init.txt</span></code></pre>
      </div>
      <p>
       If you installed MySQL to a different location, adjust
                the
       <span class="command">
        <strong>
         cd
        </strong>
       </span>
       command accordingly.
      </p>
      <p>
       The server executes the contents of the file named by
                the
       <a class="link" href="server-system-variables.html#sysvar_init_file">
        <code class="literal">
         init_file
        </code>
       </a>
       system
                variable at startup, changing the
       <code class="literal">
        'root'@'localhost'
       </code>
       account password.
      </p>
      <p>
       To have server output to appear in the console window
                rather than in a log file, add the
       <a class="link" href="server-options.html#option_mysqld_console">
        <code class="option">
         --console
        </code>
       </a>
       option to the
       <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
        <span class="command">
         <strong>
          mysqld
         </strong>
        </span>
       </a>
       command.
      </p>
      <p>
       If you installed MySQL using the MySQL Installation
                Wizard, you may need to specify a
       <a class="link" href="option-file-options.html#option_general_defaults-file">
        <code class="option">
         --defaults-file
        </code>
       </a>
       option.
                For example:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa28467223"><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">C:\&gt;</span><span class="token command"> mysqld</span>
         <span class="token constant">--defaults-file</span>=<span class="token atrule">"C:\\ProgramData\\MySQL\\MySQL Server 8.4\\my.ini"</span>
         <span class="token constant">--init-file</span><span class="token attr-value"><span class="token punctuation">=</span>C:\\mysql-init.txt</span></code></pre>
      </div>
      <p>
       The appropriate
       <a class="link" href="option-file-options.html#option_general_defaults-file">
        <code class="option">
         --defaults-file
        </code>
       </a>
       setting
                can be found using the Services Manager: From the
       <span class="guimenu">
        Start
       </span>
       menu, select
       <span class="guisubmenu">
        Control Panel
       </span>
       , then
       <span class="guisubmenu">
        Administrative Tools
       </span>
       , then
       <span class="guimenuitem">
        Services
       </span>
       . Find the MySQL
                service in the list, right-click it, and choose the
       <code class="literal">
        Properties
       </code>
       option. The
       <code class="literal">
        Path
                to executable
       </code>
       field contains the
       <a class="link" href="option-file-options.html#option_general_defaults-file">
        <code class="option">
         --defaults-file
        </code>
       </a>
       setting.
      </p>
     </li>
     <li class="listitem">
      <p>
       After the server has started successfully, delete
       <code class="filename">
        C:\mysql-init.txt
       </code>
       .
      </p>
     </li>
    </ol>
   </div>
   <p>
    You should now be able to connect to the MySQL server as
    <code class="literal">
     root
    </code>
    using the new password. Stop the
            MySQL server and restart it normally. If you run the server
            as a service, start it from the Windows Services window. If
            you start the server manually, use whatever command you
            normally use.
   </p>
  </div>
  <div class="section">
   <div class="titlepage">
    <div>
     <div>
      <h5 class="title">
       <a name="resetting-permissions-unix">
       </a>
       B.3.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems
      </h5>
     </div>
    </div>
   </div>
   <p>
    On Unix, use the following procedure to reset the password
            for the MySQL
    <code class="literal">
     'root'@'localhost'
    </code>
    account.
            To change the password for a
    <code class="literal">
     root
    </code>
    account
            with a different host name part, modify the instructions to
            use that host name.
   </p>
   <p>
    The instructions assume that you start the MySQL server from
            the Unix login account that you normally use for running it.
            For example, if you run the server using the
    <code class="literal">
     mysql
    </code>
    login account, you should log in as
    <code class="literal">
     mysql
    </code>
    before using the instructions.
            Alternatively, you can log in as
    <code class="literal">
     root
    </code>
    ,
            but in this case you
    <span class="emphasis">
     <em>
      must
     </em>
    </span>
    start
    <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
     <span class="command">
      <strong>
       mysqld
      </strong>
     </span>
    </a>
    with the
    <a class="link" href="server-options.html#option_mysqld_user">
     <code class="option">
      --user=mysql
     </code>
    </a>
    option. If you
            start the server as
    <code class="literal">
     root
    </code>
    without using
    <a class="link" href="server-options.html#option_mysqld_user">
     <code class="option">
      --user=mysql
     </code>
    </a>
    , the server may
            create
    <code class="literal">
     root
    </code>
    -owned files in the data
            directory, such as log files, and these may cause
            permission-related problems for future server startups. If
            that happens, you must either change the ownership of the
            files to
    <code class="literal">
     mysql
    </code>
    or remove them.
   </p>
   <div class="orderedlist">
    <ol class="orderedlist" type="1">
     <li class="listitem">
      <p>
       Log on to your system as the Unix user that the MySQL
                server runs as (for example,
       <code class="literal">
        mysql
       </code>
       ).
      </p>
     </li>
     <li class="listitem">
      <p>
       Stop the MySQL server if it is running. Locate the
       <code class="filename">
        .pid
       </code>
       file that contains the
                server's process ID. The exact location and name of this
                file depend on your distribution, host name, and
                configuration. Common locations are
       <code class="filename">
        /var/lib/mysql/
       </code>
       ,
       <code class="filename">
        /var/run/mysqld/
       </code>
       , and
       <code class="filename">
        /usr/local/mysql/data/
       </code>
       . Generally,
                the file name has an extension of
       <code class="filename">
        .pid
       </code>
       and begins with either
       <code class="filename">
        mysqld
       </code>
       or your system's host name.
      </p>
      <p>
       Stop the MySQL server by sending a normal
       <code class="literal">
        kill
       </code>
       (not
       <code class="literal">
        kill -9
       </code>
       )
                to the
       <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
        <span class="command">
         <strong>
          mysqld
         </strong>
        </span>
       </a>
       process. Use the actual
                path name of the
       <code class="filename">
        .pid
       </code>
       file in the
                following command:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa34649528"><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">kill</span> `cat /mysql-data-directory/host_name<span class="token punctuation">.</span>pid`</code></pre>
      </div>
      <p>
       Use backticks (not forward quotation marks) with the
       <code class="literal">
        cat
       </code>
       command. These cause the output
                of
       <code class="literal">
        cat
       </code>
       to be substituted into the
       <code class="literal">
        kill
       </code>
       command.
      </p>
     </li>
     <li class="listitem">
      <p>
       Create a text file containing the password-assignment
                statement on a single line. Replace the password with
                the password that you want to use.
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa15969542"><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-sql"><span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'root'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'MyNewPass'</span><span class="token punctuation">;</span></code></pre>
      </div>
     </li>
     <li class="listitem">
      <p>
       Save the file. This example assumes that you name the
                file
       <code class="filename">
        /home/me/mysql-init
       </code>
       . The file
                contains the password, so do not save it where it can be
                read by other users. If you are not logged in as
       <code class="literal">
        mysql
       </code>
       (the user the server runs as),
                make sure that the file has permissions that permit
       <code class="literal">
        mysql
       </code>
       to read it.
      </p>
     </li>
     <li class="listitem">
      <p>
       Start the MySQL server with the
       <a class="link" href="server-system-variables.html#sysvar_init_file">
        <code class="literal">
         init_file
        </code>
       </a>
       system
                variable set to name the file:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa15834741"><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">mysqld</span> <span class="token constant">--init-file</span><span class="token attr-value"><span class="token punctuation">=</span>/home/me/mysql-init</span> &amp;</code></pre>
      </div>
      <p>
       The server executes the contents of the file named by
                the
       <a class="link" href="server-system-variables.html#sysvar_init_file">
        <code class="literal">
         init_file
        </code>
       </a>
       system
                variable at startup, changing the
       <code class="literal">
        'root'@'localhost'
       </code>
       account password.
      </p>
      <p>
       Other options may be necessary as well, depending on how
                you normally start your server. For example,
       <a class="link" href="option-file-options.html#option_general_defaults-file">
        <code class="option">
         --defaults-file
        </code>
       </a>
       may be
                needed before the
       <a class="link" href="server-system-variables.html#sysvar_init_file">
        <code class="literal">
         init_file
        </code>
       </a>
       argument.
      </p>
     </li>
     <li class="listitem">
      <p>
       After the server has started successfully, delete
       <code class="filename">
        /home/me/mysql-init
       </code>
       .
      </p>
     </li>
    </ol>
   </div>
   <p>
    You should now be able to connect to the MySQL server as
    <code class="literal">
     root
    </code>
    using the new password. Stop the
            server and restart it normally.
   </p>
  </div>
  <div class="section">
   <div class="titlepage">
    <div>
     <div>
      <h5 class="title">
       <a name="resetting-permissions-generic">
       </a>
       B.3.3.2.3 Resetting the Root Password: Generic Instructions
      </h5>
     </div>
    </div>
   </div>
   <p>
    The preceding sections provide password-resetting
            instructions specifically for Windows and Unix and Unix-like
            systems. Alternatively, on any platform, you can reset the
            password using 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 (but this
            approach is less secure):
   </p>
   <div class="orderedlist">
    <ol class="orderedlist" type="1">
     <li class="listitem">
      <p>
       Stop the MySQL server if necessary, then restart it with
                the
       <a class="link" href="server-options.html#option_mysqld_skip-grant-tables">
        <code class="option">
         --skip-grant-tables
        </code>
       </a>
       option. This enables anyone to connect without a
                password and with all privileges, and disables
                account-management statements such as
       <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement">
        <code class="literal">
         ALTER USER
        </code>
       </a>
       and
       <a class="link" href="set-password.html" title="15.7.1.10 SET PASSWORD Statement">
        <code class="literal">
         SET PASSWORD
        </code>
       </a>
       . Because
                this is insecure, if the server is started with the
       <a class="link" href="server-options.html#option_mysqld_skip-grant-tables">
        <code class="option">
         --skip-grant-tables
        </code>
       </a>
       option, it also disables remote connections by enabling
       <a class="link" href="server-system-variables.html#sysvar_skip_networking">
        <code class="literal">
         skip_networking
        </code>
       </a>
       . On
                Windows platforms, this means you must also enable
       <a class="link" href="server-system-variables.html#sysvar_shared_memory">
        <code class="literal">
         shared_memory
        </code>
       </a>
       or
       <a class="link" href="server-system-variables.html#sysvar_named_pipe">
        <code class="literal">
         named_pipe
        </code>
       </a>
       ; otherwise
                the server cannot start.
      </p>
     </li>
     <li class="listitem">
      <p>
       Connect to the MySQL server using 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; no password is
                necessary because the server was started with
       <a class="link" href="server-options.html#option_mysqld_skip-grant-tables">
        <code class="option">
         --skip-grant-tables
        </code>
       </a>
       :
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa2723564"><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">mysql</span></code></pre>
      </div>
     </li>
     <li class="listitem">
      <p>
       In the
       <code class="literal">
        mysql
       </code>
       client, tell the server
                to reload the grant tables so that account-management
                statements work:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa99734197"><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-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">FLUSH</span> <span class="token keyword">PRIVILEGES</span><span class="token punctuation">;</span></code></pre>
      </div>
      <p>
       Then change the
       <code class="literal">
        'root'@'localhost'
       </code>
       account password. Replace the password with the password
                that you want to use. To change the password for a
       <code class="literal">
        root
       </code>
       account with a different host
                name part, modify the instructions to use that host
                name.
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa40891106"><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-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'root'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'MyNewPass'</span><span class="token punctuation">;</span></code></pre>
      </div>
     </li>
    </ol>
   </div>
   <p>
    You should now be able to connect to the MySQL server as
    <code class="literal">
     root
    </code>
    using the new password. Stop the
            server and restart it normally (without the
    <a class="link" href="server-options.html#option_mysqld_skip-grant-tables">
     <code class="option">
      --skip-grant-tables
     </code>
    </a>
    option
            and without enabling the
    <a class="link" href="server-system-variables.html#sysvar_skip_networking">
     <code class="literal">
      skip_networking
     </code>
    </a>
    system
            variable).
   </p>
  </div>
 </div>
 <br/>
</div>
