Place of all tech articles

techarticles

  • Home
  • About
  • Contact Info

Recover MySQL 5.7 root Password in Redhat/CentOS 7

12th August, 2017 · techinf1 1 Comment

You can recover MySQL 5.7 root Password with following 9  easy steps. These commands will work in Redhat/CentOS 7

Step-1: Stop MySQL server

systemctl stop mysqld

 

Step-2: Set the mySQL environment option

systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

 

Step-3: Start mysql usig the options you just set

systemctl start mysqld

 

Step-4:Login as root

mysql -u root

 

Step-5: Update the root user password with these mysql commands

mysql> UPDATE mysql.user SET authentication_string = PASSWORD('YourNewPassword')
-> WHERE User = 'root' AND Host = 'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit

 

Step-6: Stop mysql

systemctl stop mysqld

 

Step-7: Unset the mySQL envitroment option so it starts normally next time

systemctl unset-environment MYSQLD_OPTS

 

Step-8: Start mysql normally:

systemctl start mysqld

 

Step-9: Try to login using your new password

mysql -u root -p

 

You can download the script from MySQL password recovery.  Follow the steps to recover password automatically

Step-1: Give execution permission to the scripts

chmod +x mysql_password_recovery.sh

Step-2 : Run the script

./mysql_password_recovery.sh YourNewPassword

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Posted in Database, MySQL |
« SSH login without password in Linux

One thought on “Recover MySQL 5.7 root Password in Redhat/CentOS 7”

  1. ryan says:
    December 29, 2020 at 10:37 am

    Instead of the UPDATE command I used the ALTER command from the MySQL Developers website. The UPDATE command did not work for me.
    Thanks for this article!

    Reply

Leave a Reply Cancel reply

Android App to challenge math ability
MathQuiz

Top Posts

  • Optimize MySQL table_open_cache
  • Optimize MySQL query_cache_size
  • Install OCI8 on CentOS/Redhat/Fedora
  • Optimize MySQL tmp_table_size
  • Recover MySQL 5.7 root Password in Redhat/CentOS 7

Recent Posts

  • Recover MySQL 5.7 root Password in Redhat/CentOS 7
  • SSH login without password in Linux
  • How to write automated FTP script in Linux
  • Installing Nginx with PHP support
  • How to access HTML5 local storage

Follow US

Follow US

Categories

© Techinfobest is the house of tech articles
  • About
  • aStore
  • Contact Info
  • google pagerank checker
  • SEO Keyword Rank
  • SEO Page Audit
  • Tools
  • whois