How To Recover Forgotten MySQL Root Password

  • 7020580
  • 07-Mar-2008
  • 01-Sep-2017


MySQL 5.x


When attempting to follow the step in the Retain documentation for creating the root password, there is an "access denied" error; or the customer cannot remember the MySQL root password (not to be confused with the Linux root password).


This knowledgebase (KB) article is provided for informational purposes only and as a courtesy service to you, our customer. GWAVA Technical Support does not have any database administration (DBA) expertise, nor does it provide DBA services or support. GWAVA is not responsible for the results of implementing any of the concepts contained in this KB article. Implementation of any of the concepts suggested in this KB article shall be done entirely at your own and sole risk, and GWAVA does not provide any kind of warranties whatsoever resulting from your decision of implementing any of the KB article’s concepts. It is up to you to do any research and to ensure yourself that any implementation and setup of any of the KB article’s concepts in your database system is correctly and properly executed. It is imperative that you have backups of your database system and storage directory before making any implementation. If you don’t have any DBA expertise, you should consult with a DBA expert before any implementation of the KB article’s concepts.  Under no circumstances, shall GWAVA, or any of its employees, be liable, in contract, tort, delict or otherwise, whether negligence is provable or not, for any direct, indirect, incidental, special, punitive, consequential or other damages, loss, cost or liability whatsoever that would result from or are related to the implementation of any of the concepts suggested in the KB article.

To the extent permitted by applicable law, GWAVA shall not be liable to you for any special, consequential, direct, indirect or similar damages, including any loss of data, arising out from migrating any type of messages, attachments, database, metadata in your Retain system to another server and/or location.

You can recover MySQL database server password in 6 easy steps.  We recommend that you first back up your database before taking these steps.

1.  Stop MySQL service:  /etc/init.d/mysql stop or rcmysql stop

2.  Start the MySQL server without a password: mysqld_safe --skip-grant-tables &

3.  Connect to the MySQL server: mysql -u root

4.  Set a new MySQL root user password (note - include the semicolon at the end of each command as shown):

mysql> use mysql;
mysql> update user set password=PASSWORD("[new password]") where User='root';

EXAMPLE: update user set password=PASSWORD("gW83#n67H") where User='root';

mysql> flush privileges;
mysql> quit

5.  Stop MySQL server: /etc/init.d/mysql stop or rcmysql stop

6.  Start MySQL server:  /etc/init.d/mysql start or rcmysql start

7.  Test the new password: mysql -u root -p

If working, the password will allow access and show the following:

Additional Information

This article was originally published in the GWAVA knowledgebase as article ID 220.