Join the community today
Become a Member

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

    468
    90
    28
    Nov 22, 2014
    Virginia, USA
    Ratings:
    +135
    Local Time:
    1:56 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:
    7:56 AM
    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.
     
    • Like Like x 1
  3. Matt Williams

    Matt Williams WordPress Fanatic

    468
    90
    28
    Nov 22, 2014
    Virginia, USA
    Ratings:
    +135
    Local Time:
    1:56 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:
    7:56 AM
    1.7.9
    5.5.41
    What operating system are you using ?
     
  5. Matt Williams

    Matt Williams WordPress Fanatic

    468
    90
    28
    Nov 22, 2014
    Virginia, USA
    Ratings:
    +135
    Local Time:
    1:56 AM
    latest
    10
    centOS 6
     
  6. mgaidia

    mgaidia New Member

    23
    11
    3
    Dec 4, 2014
    Austria
    Ratings:
    +12
    Local Time:
    7:56 AM
    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
    • Like Like x 3
    • Informative Informative x 1
  7. Matt Williams

    Matt Williams WordPress Fanatic

    468
    90
    28
    Nov 22, 2014
    Virginia, USA
    Ratings:
    +135
    Local Time:
    1:56 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:
    7:56 AM
    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.
     
    • Like Like x 1
  9. eva2000

    eva2000 Administrator Staff Member

    30,178
    6,786
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,139
    Local Time:
    3:56 PM
    Nginx 1.13.x
    MariaDB 5.5