mysql · database · how-to · mariadb

How-to reset mysql root password

Problem

You forget or don't know administrator password for mysql or mariaDB. You should have access to server (terminal or ssh)

Solution

To reset mysql administrator (root) password you should:

    1. Stop database:
    sudo systemctl stop mysql  
    
    2. Start safe-mode:
    sudo mysqld_safe --skip-grant-tables &  
    
    3. Set new password:
    mysql -uroot -e "UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';"  
    
    4. Restart database:
    sudo systemctl restart mysql  
    

Full solution

sudo systemctl stop mysql  
sudo mysqld_safe --skip-grant-tables &  
mysql -uroot -e "UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';"  
sudo systemctl restart mariadb  

Read also

http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

Published:
comments powered by Disqus