Learn about Centmin Mod LEMP Stack today
Register Now

Recovering a lost mysql root password

Discussion in 'Install & Upgrades or Pre-Install Questions' started by Matt Williams, Jan 26, 2015.

  1. Matt Williams

    Matt Williams WordPress Fanatic

    537
    104
    43
    Nov 22, 2014
    Virginia, USA
    Ratings:
    +157
    Local Time:
    10:02 AM
    latest
    10
    I'm digging through install logs and I can't seem to find this no where. Is their an easier way to find this?

     
  2. mgaidia

    mgaidia New Member

    23
    11
    3
    Dec 4, 2014
    Austria
    Ratings:
    +12
    Local Time:
    4:02 PM
    1.7.9
    5.5.41
    you can always start mysql in safemode (equivalent of single user mode in linux) and reset the root password.
     
  3. Matt Williams

    Matt Williams WordPress Fanatic

    537
    104
    43
    Nov 22, 2014
    Virginia, USA
    Ratings:
    +157
    Local Time:
    10:02 AM
    latest
    10
    How exactly would I do that? - Thank you for your response mgaidia!
     
  4. mgaidia

    mgaidia New Member

    23
    11
    3
    Dec 4, 2014
    Austria
    Ratings:
    +12
    Local Time:
    4:02 PM
    1.7.9
    5.5.41
    What operating system are you using ?
     
  5. Matt Williams

    Matt Williams WordPress Fanatic

    537
    104
    43
    Nov 22, 2014
    Virginia, USA
    Ratings:
    +157
    Local Time:
    10:02 AM
    latest
    10
    centOS 6
     
  6. mgaidia

    mgaidia New Member

    23
    11
    3
    Dec 4, 2014
    Austria
    Ratings:
    +12
    Local Time:
    4:02 PM
    1.7.9
    5.5.41
    Execute the following in order:
    Code:
    sudo /etc/init.d/mysqld stop
    sudo mysqld_safe --skip-grant-tables &
    mysql -u root
    use mysql;
    update user set password=PASSWORD("PUT_A_NEW_PASSWD_HERE") where User='root';
    flush privileges;
    quit or ctrl+D or exit
    sudo /etc/init.d/mysqld stop
    sudo /etc/init.d/mysqld start
    
     
    Last edited by a moderator: Mar 27, 2016
  7. Matt Williams

    Matt Williams WordPress Fanatic

    537
    104
    43
    Nov 22, 2014
    Virginia, USA
    Ratings:
    +157
    Local Time:
    10:02 AM
    latest
    10
    Thank you! Worked like a charm. However, I had to use the short codes mysqlstop/start but other then that, worked perfect! Thanks again!​
     
  8. mgaidia

    mgaidia New Member

    23
    11
    3
    Dec 4, 2014
    Austria
    Ratings:
    +12
    Local Time:
    4:02 PM
    1.7.9
    5.5.41
    I used /etc/init.d/mysqld because it uses the absolute path which should work on all systems. I always try to avoid aliases when giving instruction to a third party.
    You are most welcome by the way.
     
  9. eva2000

    eva2000 Administrator Staff Member

    53,247
    12,117
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,655
    Local Time:
    12:02 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+